~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to Xgamma/src/applet-init.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <stdio.h>
 
30
#include <errno.h>
 
31
#include <X11/Xos.h>
 
32
#include <X11/Xlib.h>
 
33
#include <X11/Xutil.h>
 
34
#include <X11/extensions/xf86vmode.h>
 
35
#include <ctype.h>
 
36
#include <stdlib.h>
 
37
 
 
38
#include <cairo-dock.h>
 
39
 
 
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"
 
45
 
 
46
static gboolean s_bVideoExtensionChecked = FALSE;
 
47
 
 
48
 
 
49
CD_APPLET_DEFINITION ("Xgamma",
 
50
        1, 6, 2,
 
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)")
 
58
 
 
59
 
 
60
CD_APPLET_INIT_BEGIN
 
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;
 
65
        
 
66
        if (! s_bVideoExtensionChecked)
 
67
        {
 
68
                s_bVideoExtensionChecked = TRUE;
 
69
                
 
70
                const Display *dpy = cairo_dock_get_Xdisplay ();
 
71
                if (dpy == NULL)
 
72
                {
 
73
                        cd_warning ("Xgamma : unable to get X display");
 
74
                        return ;
 
75
                }
 
76
                
 
77
                //#ifdef XF86VidModeQueryVersion
 
78
                int MajorVersion, MinorVersion;
 
79
                if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion))
 
80
                {
 
81
                        cd_warning ("Xgamma : unable to query video extension version");
 
82
                        return ;
 
83
                }
 
84
                //#endif
 
85
                
 
86
                //#ifdef XF86VidModeQueryExtension
 
87
                int EventBase, ErrorBase;
 
88
                if (!XF86VidModeQueryExtension(dpy, &EventBase, &ErrorBase))
 
89
                {
 
90
                        cd_warning ("Xgamma : unable to query video extension information");
 
91
                        return ;
 
92
                }
 
93
                //#endif
 
94
                
 
95
                myData.bVideoExtensionOK = TRUE;
 
96
                
 
97
                if (myConfig.fInitialGamma != 0)
 
98
                {
 
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);
 
106
                }
 
107
        }
 
108
        
 
109
        if (myDesklet)  // on cree le widget pour avoir qqch a afficher dans le desklet.
 
110
        {
 
111
                xgamma_build_and_show_widget ();
 
112
                CD_APPLET_SET_STATIC_DESKLET;
 
113
        }
 
114
        else
 
115
                CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
 
116
CD_APPLET_INIT_END
 
117
 
 
118
 
 
119
CD_APPLET_STOP_BEGIN
 
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;
 
125
CD_APPLET_STOP_END
 
126
 
 
127
 
 
128
CD_APPLET_RELOAD_BEGIN
 
129
        //\_______________ On recharge les donnees qui ont pu changer.
 
130
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
131
        {
 
132
                if (! myData.pWidget)
 
133
                {
 
134
                        if (myDesklet)  // on cree le widget pour avoir qqch a afficher dans le desklet.
 
135
                                xgamma_build_and_show_widget ();
 
136
                }
 
137
                else if (CD_APPLET_MY_CONTAINER_TYPE_CHANGED)
 
138
                {
 
139
                        if (myDesklet)  // il faut passer du dialogue au desklet.
 
140
                        {
 
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;
 
147
                        }
 
148
                        else  // il faut passer du desklet au dialogue
 
149
                        {
 
150
                                myData.pDialog = xgamma_build_dialog ();
 
151
                                cairo_dock_hide_dialog (myData.pDialog);
 
152
                        }
 
153
                }
 
154
        }
 
155
        
 
156
        if (myDock)
 
157
                CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;
 
158
CD_APPLET_RELOAD_END