Debian Codegraph @

Xgamma/src/applet-notifications.c

raw
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 <stdlib.h>
21 #include <string.h>
22 #include <glib/gi18n.h>
23 #include <cairo-dock.h>
24
25 #include "applet-struct.h"
26 #include "applet-xgamma.h"
27 #include "applet-notifications.h"
28
29
30 CD_APPLET_ON_CLICK_BEGIN
31 if (myDock)
32 {
33 xgamma_build_dialog_simple ();
34 }
35 CD_APPLET_ON_CLICK_END
36
37
38 static void _cd_xgamma_set_up_gamma_correction (void)
39 {
40 double fGamma = xgamma_get_gamma (&myData.Xgamma);
41 if (fGamma >= 0)
42 {
43 //\___________________ On construit notre widget si c'est la 1ere fois.
44 if (myData.pWidget == NULL)
45 {
46 xgamma_build_and_show_widget ();
47 }
48 else
49 {
50 //\___________________ On lui met les valeurs a jour, sans appeler les callbacks.
51 g_signal_handler_block (myData.pGlobalScale, myData.iGloalScaleSignalID);
52 g_signal_handler_block (myData.pRedScale, myData.iRedScaleSignalID);
53 g_signal_handler_block (myData.pGreenScale, myData.iGreenScaleSignalID);
54 g_signal_handler_block (myData.pBlueScale, myData.iBlueScaleSignalID);
55
56 gtk_range_set_value (GTK_RANGE (myData.pGlobalScale), fGamma);
57 gtk_range_set_value (GTK_RANGE (myData.pRedScale), myData.Xgamma.red);
58 gtk_range_set_value (GTK_RANGE (myData.pGreenScale), myData.Xgamma.green);
59 gtk_range_set_value (GTK_RANGE (myData.pBlueScale), myData.Xgamma.blue);
60 myData.XoldGamma = myData.Xgamma;
61
62 g_signal_handler_unblock (myData.pGlobalScale, myData.iGloalScaleSignalID);
63 g_signal_handler_unblock (myData.pRedScale, myData.iRedScaleSignalID);
64 g_signal_handler_unblock (myData.pGreenScale, myData.iGreenScaleSignalID);
65 g_signal_handler_unblock (myData.pBlueScale, myData.iBlueScaleSignalID);
66
67 if (myData.pDialog != NULL)
68 {
69 gldi_dialog_unhide (myData.pDialog);
70 }
71 }
72 }
73 }
74
75 static void _cd_xgamma_remember_current_gamma (GtkMenuItem *menu_item, GldiModuleInstance *myApplet)
76 {
77 double fGamma = xgamma_get_gamma (&myData.Xgamma);
78 g_return_if_fail (fGamma > 0);
79
80 cairo_dock_update_conf_file (CD_APPLET_MY_CONF_FILE,
81 G_TYPE_DOUBLE, "Configuration", "initial gamma", fGamma,
82 G_TYPE_INVALID);
83 }
84 CD_APPLET_ON_BUILD_MENU_BEGIN
85 if (myDock)
86 {
87 gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Set up gamma correction"), D_("middle-click"));
88 CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GLDI_ICON_NAME_DIALOG_INFO, _cd_xgamma_set_up_gamma_correction, CD_APPLET_MY_MENU);
89 g_free (cLabel);
90 }
91 CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Apply current luminosity on startup"), GLDI_ICON_NAME_DIALOG_WARNING, _cd_xgamma_remember_current_gamma, CD_APPLET_MY_MENU);
92 CD_APPLET_ON_BUILD_MENU_END
93
94
95 CD_APPLET_ON_MIDDLE_CLICK_BEGIN
96 if (myDock)
97 {
98 _cd_xgamma_set_up_gamma_correction ();
99 }
100 CD_APPLET_ON_MIDDLE_CLICK_END
101
102
103 static gboolean _on_scroll (gpointer data)
104 {
105 cd_debug ("%s (%d)", __func__, myData.iScrollCount);
106 if (myData.iScrollCount != 0)
107 xgamma_add_gamma (&myData.Xgamma, myData.iScrollCount);
108 myData.iSidScrollAction = 0;
109 myData.iScrollCount = 0;
110 return FALSE;
111 }
112 CD_APPLET_ON_SCROLL_BEGIN
113 myData.iScrollCount += (CD_APPLET_SCROLL_UP ? 1 : -1);
114 if (myData.iSidScrollAction == 0)
115 myData.iSidScrollAction = g_timeout_add (200, (GSourceFunc) _on_scroll, NULL);
116 CD_APPLET_ON_SCROLL_END
117
118
119 void cd_xgamma_on_keybinding_pull (const gchar *keystring, gpointer user_data)
120 {
121 xgamma_add_gamma (&myData.Xgamma, +1);
122 }
123
124 void cd_xgamma_on_keybinding_pull2 (const gchar *keystring, gpointer user_data)
125 {
126 xgamma_add_gamma (&myData.Xgamma, -1);
127 }