~noskcaj/ubuntu/trusty/xfce4-power-manager/systemd

« back to all changes in this revision

Viewing changes to src/xfpm-backlight.c

  • Committer: Jackson Doak
  • Date: 2014-01-19 20:07:41 UTC
  • Revision ID: noskcaj@ubuntu.com-20140119200741-1wja2aktv5zyz8d2
Add patches from debian svn branch to fix systemd. LP: 1222021

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include "xfpm-debug.h"
43
43
#include "xfpm-icons.h"
44
44
 
 
45
#include "gsd-media-keys-window.h"
 
46
 
45
47
static void xfpm_backlight_finalize     (GObject *object);
46
48
 
 
49
static void xfpm_backlight_create_popup (XfpmBacklight *backlight);
 
50
 
47
51
#define ALARM_DISABLED 9
 
52
#define BRIGHTNESS_POPUP_SIZE   180
48
53
 
49
54
#define XFPM_BACKLIGHT_GET_PRIVATE(o) \
50
55
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_BACKLIGHT, XfpmBacklightPrivate))
58
63
    XfpmButton     *button;
59
64
    XfpmNotify     *notify;
60
65
    
 
66
    GtkWidget      *osd;
61
67
    NotifyNotification *n;
62
68
    
 
69
    
 
70
    gulong          destroy_id;
 
71
    
63
72
    gboolean        has_hw;
64
73
    gboolean        on_battery;
65
74
    
114
123
    
115
124
    backlight = XFPM_BACKLIGHT (data);
116
125
    
 
126
    if ( backlight->priv->osd )
 
127
    {
 
128
        gtk_widget_destroy (backlight->priv->osd);
 
129
        backlight->priv->osd = NULL;
 
130
    }
 
131
    
117
132
    if ( backlight->priv->n )
118
133
    {
119
134
        g_object_unref (backlight->priv->n);
124
139
}
125
140
 
126
141
static void
 
142
xfpm_backlight_composited_changed_cb (XfpmBacklight *backlight)
 
143
{
 
144
    xfpm_backlight_destroy_popup (backlight);
 
145
    xfpm_backlight_create_popup (backlight);
 
146
}
 
147
 
 
148
static void
127
149
xfpm_backlight_show_notification (XfpmBacklight *backlight, gfloat value)
128
150
{
129
 
    gchar *summary;
130
 
 
131
 
    /* create the notification on demand */
 
151
    gint i;
 
152
    
 
153
    static const char *display_icon_name[] = 
 
154
    {
 
155
        "notification-display-brightness-off",
 
156
        "notification-display-brightness-low",
 
157
        "notification-display-brightness-medium",
 
158
        "notification-display-brightness-high",
 
159
        "notification-display-brightness-full",
 
160
        NULL
 
161
    };
 
162
    
132
163
    if ( backlight->priv->n == NULL )
133
164
    {
134
 
        backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify,
135
 
                                                           "",
136
 
                                                           "",
137
 
                                                           "xfpm-brightness-lcd",
138
 
                                                           0,
 
165
        backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify, 
 
166
                                                           " ", 
 
167
                                                           "", 
 
168
                                                           NULL, 
 
169
                                                           0, 
139
170
                                                           XFPM_NOTIFY_NORMAL,
140
171
                                                           NULL);
141
172
    }
142
 
 
143
 
    /* generate a human-readable summary for the notification */
144
 
    summary = g_strdup_printf (_("Brightness: %.0f percent"), value);
145
 
    notify_notification_update (backlight->priv->n, summary, NULL, NULL);
146
 
    g_free (summary);
147
 
    
148
 
    /* add the brightness value to the notification */
149
 
    notify_notification_set_hint_int32 (backlight->priv->n, "value", value);
150
 
    
151
 
    /* show the notification */
 
173
    
 
174
    i = (gint)value / 25;
 
175
    
 
176
    if ( i > 4 || i < 0 )
 
177
        return;
 
178
    
 
179
    notify_notification_set_hint_int32  (backlight->priv->n,
 
180
                                         "value",
 
181
                                         value);
 
182
    
 
183
    notify_notification_set_hint_string (backlight->priv->n,
 
184
                                         "x-canonical-private-synchronous",
 
185
                                         "brightness");
 
186
    
 
187
    notify_notification_update (backlight->priv->n,
 
188
                                " ",
 
189
                                "",
 
190
                                display_icon_name[i]);
 
191
                                
152
192
    notify_notification_show (backlight->priv->n, NULL);
153
193
}
154
194
 
155
195
static void
 
196
xfpm_backlight_create_popup (XfpmBacklight *backlight)
 
197
{
 
198
    if ( backlight->priv->osd != NULL )
 
199
        return;
 
200
        
 
201
    backlight->priv->osd = gsd_media_keys_window_new ();
 
202
    gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->osd),
 
203
                                             XFPM_DISPLAY_BRIGHTNESS_ICON,
 
204
                                             TRUE);
 
205
    gtk_window_set_position (GTK_WINDOW (backlight->priv->osd), GTK_WIN_POS_CENTER);
 
206
    
 
207
    g_signal_connect_swapped (backlight->priv->osd, "composited-changed",
 
208
                              G_CALLBACK (xfpm_backlight_composited_changed_cb), backlight);
 
209
                              
 
210
}
 
211
 
 
212
static void
156
213
xfpm_backlight_show (XfpmBacklight *backlight, gint level)
157
214
{
158
215
    gfloat value;
 
216
    gboolean sync_notify;
 
217
    gboolean show_popup;
159
218
    
160
219
    XFPM_DEBUG ("Level %u", level);
161
220
    
 
221
    g_object_get (G_OBJECT (backlight->priv->conf),
 
222
                  SHOW_BRIGHTNESS_POPUP, &show_popup,
 
223
                  NULL);
 
224
                  
 
225
    if ( !show_popup )
 
226
        goto out;
 
227
    
 
228
    g_object_get (G_OBJECT (backlight->priv->notify),
 
229
                  "sync", &sync_notify,
 
230
                  NULL);
 
231
    
162
232
    value = (gfloat) 100 * level / backlight->priv->max_level;
163
 
    xfpm_backlight_show_notification (backlight, value);
 
233
    
 
234
    if ( !sync_notify ) /*Notification server doesn't support sync notifications*/
 
235
    {
 
236
        xfpm_backlight_create_popup (backlight);
 
237
        gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (backlight->priv->osd),
 
238
                                                round (value));
 
239
        if ( !GTK_WIDGET_VISIBLE (backlight->priv->osd))
 
240
            gtk_window_present (GTK_WINDOW (backlight->priv->osd));
 
241
    }
 
242
    else
 
243
    {
 
244
        xfpm_backlight_show_notification (backlight, value);
 
245
    }
 
246
    
 
247
    if ( backlight->priv->destroy_id != 0 )
 
248
    {
 
249
        g_source_remove (backlight->priv->destroy_id);
 
250
        backlight->priv->destroy_id = 0;
 
251
    }
 
252
    
 
253
out:
 
254
    /* Release the memory after 60 seconds */
 
255
    backlight->priv->destroy_id = g_timeout_add_seconds (60, (GSourceFunc) xfpm_backlight_destroy_popup, backlight);
164
256
}
165
257
 
166
258
 
294
386
    backlight->priv->brightness = xfpm_brightness_new ();
295
387
    backlight->priv->has_hw     = xfpm_brightness_setup (backlight->priv->brightness);
296
388
    
 
389
    backlight->priv->osd    = NULL;
297
390
    backlight->priv->notify = NULL;
298
391
    backlight->priv->idle   = NULL;
299
392
    backlight->priv->conf   = NULL;
301
394
    backlight->priv->power    = NULL;
302
395
    backlight->priv->dimmed = FALSE;
303
396
    backlight->priv->block = FALSE;
 
397
    backlight->priv->destroy_id = 0;
304
398
    
305
399
    if ( !backlight->priv->has_hw )
306
400
    {