2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
33
#include <X11/Xutil.h>
34
#include <X11/extensions/xf86vmode.h>
38
#include <cairo-dock.h>
40
#include "applet-config.h"
41
#include "applet-notifications.h"
42
#include "applet-xgamma.h"
43
#include "applet-struct.h"
44
#include "applet-init.h"
46
static gboolean s_bVideoExtensionChecked = FALSE;
49
CD_APPLET_DEFINITION ("Xgamma",
51
CAIRO_DOCK_CATEGORY_CONTROLER,
52
N_("Setup the luminosity of your screen directly from your dock.\n"
53
"Scroll up/down to increase/decrease the luminosity\n"
54
"Left-click to open a dialog to setup the luminosity\n"
55
"Middle-click to set it up for each color.\n"
56
"You can also define a luminosity value that will be applied automatically on startup."),
57
"Fabounet (Fabrice Rey)")
61
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
62
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
63
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
64
CD_APPLET_REGISTER_FOR_SCROLL_EVENT;
66
if (! s_bVideoExtensionChecked)
68
s_bVideoExtensionChecked = TRUE;
70
const Display *dpy = cairo_dock_get_Xdisplay ();
73
cd_warning ("Xgamma : unable to get X display");
77
//#ifdef XF86VidModeQueryVersion
78
int MajorVersion, MinorVersion;
79
if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion))
81
cd_warning ("Xgamma : unable to query video extension version");
86
//#ifdef XF86VidModeQueryExtension
87
int EventBase, ErrorBase;
88
if (!XF86VidModeQueryExtension(dpy, &EventBase, &ErrorBase))
90
cd_warning ("Xgamma : unable to query video extension information");
95
myData.bVideoExtensionOK = TRUE;
97
if (myConfig.fInitialGamma != 0)
99
cd_message ("Applying luminosity as defined in config (gamma=%.2f)...", myConfig.fInitialGamma);
100
xgamma_get_gamma (&myData.Xgamma);
101
myConfig.fInitialGamma = MIN (GAMMA_MAX, MAX (myConfig.fInitialGamma, GAMMA_MIN));
102
myData.Xgamma.red = myConfig.fInitialGamma;
103
myData.Xgamma.blue = myConfig.fInitialGamma;
104
myData.Xgamma.green = myConfig.fInitialGamma;
105
xgamma_set_gamma (&myData.Xgamma);
109
if (myDesklet) // on cree le widget pour avoir qqch a afficher dans le desklet.
111
xgamma_build_and_show_widget ();
112
CD_APPLET_SET_STATIC_DESKLET;
115
CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
120
//\_______________ On se desabonne de nos notifications.
121
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
122
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
123
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
124
CD_APPLET_UNREGISTER_FOR_SCROLL_EVENT;
128
CD_APPLET_RELOAD_BEGIN
129
//\_______________ On recharge les donnees qui ont pu changer.
130
if (CD_APPLET_MY_CONFIG_CHANGED)
132
if (! myData.pWidget)
134
if (myDesklet) // on cree le widget pour avoir qqch a afficher dans le desklet.
135
xgamma_build_and_show_widget ();
137
else if (CD_APPLET_MY_CONTAINER_TYPE_CHANGED)
139
if (myDesklet) // il faut passer du dialogue au desklet.
141
myData.pWidget = cairo_dock_steal_widget_from_its_container (myData.pWidget);
142
cairo_dock_dialog_unreference (myData.pDialog);
143
myData.pDialog = NULL;
144
cairo_dock_add_interactive_widget_to_desklet (myData.pWidget, myDesklet);
145
cairo_dock_set_desklet_renderer_by_name (myDesklet, NULL, NULL, ! CAIRO_DOCK_LOAD_ICONS_FOR_DESKLET, NULL);
146
CD_APPLET_SET_STATIC_DESKLET;
148
else // il faut passer du desklet au dialogue
150
myData.pDialog = xgamma_build_dialog ();
151
cairo_dock_hide_dialog (myData.pDialog);
157
CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;