| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 3 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <errno.h> |
| 22 |
#include <X11/Xos.h> |
| 23 |
#include <X11/Xlib.h> |
| 24 |
#include <X11/Xutil.h> |
| 25 |
#include <X11/extensions/xf86vmode.h> |
| 26 |
#include <ctype.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <gdk/gdkx.h> |
| 29 |
|
| 30 |
#include <cairo-dock.h> |
| 31 |
|
| 32 |
#include "applet-config.h" |
| 33 |
#include "applet-notifications.h" |
| 34 |
#include "applet-xgamma.h" |
| 35 |
#include "applet-struct.h" |
| 36 |
#include "applet-init.h" |
| 37 |
|
| 38 |
static gboolean s_bVideoExtensionChecked = FALSE; |
| 39 |
|
| 40 |
|
| 41 |
CD_APPLET_DEFINE_BEGIN ("Xgamma", |
| 42 |
1, 6, 2, |
| 43 |
CAIRO_DOCK_CATEGORY_APPLET_SYSTEM, |
| 44 |
N_("Setup the luminosity of your screen directly from your dock.\n" |
| 45 |
"Scroll up/down to increase/decrease the luminosity\n" |
| 46 |
"Left-click to open a dialog to setup the luminosity\n" |
| 47 |
"Middle-click to set it up for each color.\n" |
| 48 |
"You can also define a luminosity value that will be applied automatically on startup."), |
| 49 |
"Fabounet (Fabrice Rey)") |
| 50 |
CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE |
| 51 |
CD_APPLET_ALLOW_EMPTY_TITLE |
| 52 |
CD_APPLET_REDEFINE_TITLE (N_("Screen Luminosity")) |
| 53 |
CD_APPLET_DEFINE_END |
| 54 |
|
| 55 |
|
| 56 |
CD_APPLET_INIT_BEGIN |
| 57 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 58 |
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 59 |
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 60 |
CD_APPLET_REGISTER_FOR_SCROLL_EVENT; |
| 61 |
|
| 62 |
// shortkey |
| 63 |
myData.pKeyBinding = CD_APPLET_BIND_KEY (myConfig.cShortkey, |
| 64 |
D_("Increase the brightness"), |
| 65 |
"Configuration", "shortkey", |
| 66 |
(CDBindkeyHandler) cd_xgamma_on_keybinding_pull); |
| 67 |
myData.pKeyBinding2 = CD_APPLET_BIND_KEY (myConfig.cShortkey2, |
| 68 |
D_("Decrease the brightness"), |
| 69 |
"Configuration", "shortkey", |
| 70 |
(CDBindkeyHandler) cd_xgamma_on_keybinding_pull2); |
| 71 |
|
| 72 |
if (! s_bVideoExtensionChecked) |
| 73 |
{ |
| 74 |
s_bVideoExtensionChecked = TRUE; |
| 75 |
|
| 76 |
Display *dpy = gdk_x11_get_default_xdisplay (); |
| 77 |
if (dpy == NULL) |
| 78 |
{ |
| 79 |
cd_warning ("Xgamma : unable to get X display"); |
| 80 |
return ; |
| 81 |
} |
| 82 |
|
| 83 |
//#ifdef XF86VidModeQueryVersion |
| 84 |
int MajorVersion, MinorVersion; |
| 85 |
if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) |
| 86 |
{ |
| 87 |
cd_warning ("Xgamma : unable to query video extension version"); |
| 88 |
return ; |
| 89 |
} |
| 90 |
//#endif |
| 91 |
|
| 92 |
//#ifdef XF86VidModeQueryExtension |
| 93 |
int EventBase, ErrorBase; |
| 94 |
if (!XF86VidModeQueryExtension(dpy, &EventBase, &ErrorBase)) |
| 95 |
{ |
| 96 |
cd_warning ("Xgamma : unable to query video extension information"); |
| 97 |
return ; |
| 98 |
} |
| 99 |
//#endif |
| 100 |
|
| 101 |
myData.bVideoExtensionOK = TRUE; |
| 102 |
|
| 103 |
if (myConfig.fInitialGamma != 0) |
| 104 |
{ |
| 105 |
cd_message ("Applying luminosity as defined in config (gamma=%.2f)...", myConfig.fInitialGamma); |
| 106 |
xgamma_get_gamma (&myData.Xgamma); |
| 107 |
myConfig.fInitialGamma = MIN (GAMMA_MAX, MAX (myConfig.fInitialGamma, GAMMA_MIN)); |
| 108 |
myData.Xgamma.red = myConfig.fInitialGamma; |
| 109 |
myData.Xgamma.blue = myConfig.fInitialGamma; |
| 110 |
myData.Xgamma.green = myConfig.fInitialGamma; |
| 111 |
xgamma_set_gamma (&myData.Xgamma); |
| 112 |
|
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if (myDesklet) // on cree le widget pour avoir qqch a afficher dans le desklet. |
| 117 |
{ |
| 118 |
xgamma_build_and_show_widget (); |
| 119 |
} |
| 120 |
else |
| 121 |
{ |
| 122 |
if (myConfig.cDefaultTitle == NULL && myIcon->cName == NULL) // if the label has already been set by the initial luminosity setting, don't replace it (the gamma on the X server side is not yet equal to the value we just set before). |
| 123 |
{ |
| 124 |
double fGamma = xgamma_get_gamma (&myData.Xgamma); |
| 125 |
cd_gamma_display_gamma_on_label (fGamma); |
| 126 |
} |
| 127 |
CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE; |
| 128 |
} |
| 129 |
CD_APPLET_INIT_END |
| 130 |
|
| 131 |
|
| 132 |
CD_APPLET_STOP_BEGIN |
| 133 |
//\_______________ On se desabonne de nos notifications. |
| 134 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 135 |
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 136 |
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 137 |
CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT; |
| 138 |
|
| 139 |
gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding)); |
| 140 |
gldi_object_unref (GLDI_OBJECT(myData.pKeyBinding2)); |
| 141 |
|
| 142 |
if (myData.iSidScrollAction != 0) |
| 143 |
g_source_remove (myData.iSidScrollAction); |
| 144 |
CD_APPLET_STOP_END |
| 145 |
|
| 146 |
|
| 147 |
CD_APPLET_RELOAD_BEGIN |
| 148 |
//\_______________ On recharge les donnees qui ont pu changer. |
| 149 |
if (CD_APPLET_MY_CONFIG_CHANGED) |
| 150 |
{ |
| 151 |
if (! myData.pWidget) |
| 152 |
{ |
| 153 |
if (myDesklet) // on cree le widget pour avoir qqch a afficher dans le desklet. |
| 154 |
xgamma_build_and_show_widget (); |
| 155 |
} |
| 156 |
else if (CD_APPLET_MY_CONTAINER_TYPE_CHANGED) |
| 157 |
{ |
| 158 |
if (myDesklet) // il faut passer du dialogue au desklet. |
| 159 |
{ |
| 160 |
gldi_dialog_steal_interactive_widget (myData.pDialog); |
| 161 |
gldi_object_unref (GLDI_OBJECT(myData.pDialog)); |
| 162 |
myData.pDialog = NULL; |
| 163 |
gldi_desklet_add_interactive_widget (myDesklet, myData.pWidget); |
| 164 |
CD_APPLET_SET_DESKLET_RENDERER (NULL); |
| 165 |
CD_APPLET_SET_STATIC_DESKLET; |
| 166 |
} |
| 167 |
else // il faut passer du desklet au dialogue |
| 168 |
{ |
| 169 |
gldi_desklet_steal_interactive_widget (CAIRO_DESKLET (CD_APPLET_MY_OLD_CONTAINER)); |
| 170 |
myData.pDialog = xgamma_build_dialog (); |
| 171 |
gldi_dialog_hide (myData.pDialog); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
if (myDock && myConfig.cDefaultTitle == NULL) |
| 176 |
{ |
| 177 |
double fGamma = xgamma_get_gamma (&myData.Xgamma); |
| 178 |
cd_gamma_display_gamma_on_label (fGamma); |
| 179 |
} |
| 180 |
|
| 181 |
gldi_shortkey_rebind (myData.pKeyBinding, myConfig.cShortkey, NULL); |
| 182 |
gldi_shortkey_rebind (myData.pKeyBinding2, myConfig.cShortkey2, NULL); |
| 183 |
} |
| 184 |
|
| 185 |
if (myDock) |
| 186 |
CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE; |
| 187 |
CD_APPLET_RELOAD_END |