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

« back to all changes in this revision

Viewing changes to Global-Menu/src/applet-app.c

  • Committer: Matthieu Baerts
  • Date: 2013-08-27 14:46:47 UTC
  • mto: (53.1.4 cairo-dock-plug-ins)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: matttbe@gmail.com-20130827144647-wm0kyawa8vcg0cso
Tags: upstream-3.2.99.beta1.1~20130827~bzr2928
ImportĀ upstreamĀ versionĀ 3.2.99.beta1.1~20130827~bzr2928

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 /// WINDOW CONTROLS ///
46
46
///////////////////////
47
47
 
48
 
void cd_app_menu_set_window_border (Window Xid, gboolean bWithBorder)
49
 
{
50
 
        Display *dpy = cairo_dock_get_Xdisplay();
51
 
        MwmHints mwmhints;
52
 
        Atom prop;
53
 
        memset(&mwmhints, 0, sizeof(mwmhints));
54
 
        prop = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
55
 
        mwmhints.flags = MWM_HINTS_DECORATIONS;
56
 
        mwmhints.decorations = bWithBorder;
57
 
        XChangeProperty (dpy, Xid, prop,
58
 
                prop, 32, PropModeReplace,
59
 
                (unsigned char *) &mwmhints,
60
 
                PROP_MWM_HINTS_ELEMENTS);
61
 
}
62
 
 
63
 
static void _get_window_allowed_actions (Window Xid)
64
 
{
65
 
        if (Xid == 0)
 
48
static void _get_window_allowed_actions (GldiWindowActor *actor)
 
49
{
 
50
        if (actor == NULL)
66
51
        {
67
52
                myData.bCanMinimize = FALSE;
68
53
                myData.bCanMaximize = FALSE;
69
54
                myData.bCanClose = FALSE;
70
55
                return;
71
56
        }
72
 
        
73
 
        Atom aReturnedType = 0;
74
 
        int aReturnedFormat = 0;
75
 
        unsigned long iLeftBytes, iBufferNbElements = 0;
76
 
        gulong *pXStateBuffer = NULL;
77
 
        Display *dpy = cairo_dock_get_Xdisplay ();
78
 
        Atom allowedActions = XInternAtom (dpy, "_NET_WM_ALLOWED_ACTIONS", False);
79
 
        Atom atomMinimize = XInternAtom (dpy, "_NET_WM_ACTION_MINIMIZE", False);
80
 
        Atom atomMaximizeHorz = XInternAtom (dpy, "_NET_WM_ACTION_MAXIMIZE_HORZ", False);
81
 
        Atom atomMaximizeVert = XInternAtom (dpy, "_NET_WM_ACTION_MAXIMIZE_VERT", False);
82
 
        Atom atomClose = XInternAtom (dpy, "_NET_WM_ACTION_CLOSE", False);
83
 
        
84
 
        XGetWindowProperty (dpy,
85
 
                Xid, allowedActions, 0, G_MAXULONG, False, XA_ATOM,
86
 
                &aReturnedType, &aReturnedFormat, &iBufferNbElements, &iLeftBytes, (guchar **)&pXStateBuffer);
87
 
        
88
 
        if (iBufferNbElements > 0)
89
 
        {
90
 
                myData.bCanMinimize = FALSE;
91
 
                myData.bCanMaximize = FALSE;
92
 
                myData.bCanClose = FALSE;
93
 
                guint i;
94
 
                for (i = 0; i < iBufferNbElements; i ++)
95
 
                {
96
 
                        if (pXStateBuffer[i] == atomMinimize)
97
 
                        {
98
 
                                myData.bCanMinimize = TRUE;
99
 
                        }
100
 
                        else if (pXStateBuffer[i] == atomMaximizeHorz || pXStateBuffer[i] == atomMaximizeVert)
101
 
                        {
102
 
                                myData.bCanMaximize = TRUE;
103
 
                        }
104
 
                        else if (pXStateBuffer[i] == atomClose)
105
 
                        {
106
 
                                myData.bCanClose = TRUE;
107
 
                        }
108
 
                }
109
 
        }
110
 
        else  // by default, allow all actions.
111
 
        {
112
 
                cd_warning ("couldn't get allowed actions for the window %u", Xid);
113
 
                myData.bCanMinimize = TRUE;
114
 
                myData.bCanMaximize = TRUE;
115
 
                myData.bCanClose = TRUE;
116
 
        }
117
 
 
118
 
        XFree (pXStateBuffer);
 
57
        gldi_window_can_minimize_maximize_close (actor, &myData.bCanMinimize, &myData.bCanMaximize, &myData.bCanClose);
119
58
}
120
59
 
121
 
static void _set_border (Icon *icon, CairoContainer *pContainer, gboolean bWithBorder)
 
60
static void _set_border (GldiWindowActor *actor, gboolean bWithBorder)
122
61
{
123
 
        if (icon->bIsMaximized)
124
 
                cd_app_menu_set_window_border (icon->Xid, bWithBorder);
 
62
        if (actor->bIsMaximized)
 
63
                gldi_window_set_border (actor, bWithBorder);
125
64
}
126
65
void cd_app_menu_set_windows_borders (gboolean bWithBorder)
127
66
{
128
 
        cairo_dock_foreach_applis ((CairoDockForeachIconFunc)_set_border, FALSE, GINT_TO_POINTER (bWithBorder));
 
67
        gldi_windows_foreach (FALSE, (GFunc)_set_border, GINT_TO_POINTER (bWithBorder));
129
68
}
130
69
 
131
70
 
153
92
                        CD_APP_MENU_REGISTRAR_IFACE);  // whenever it appears on the bus, we'll get it.
154
93
                
155
94
                // get the controls and menu of the current window.
156
 
                Window iActiveWindow = cairo_dock_get_current_active_window ();
 
95
                GldiWindowActor *actor = gldi_windows_get_active ();
157
96
                
158
 
                cd_app_menu_set_current_window (iActiveWindow);
 
97
                cd_app_menu_set_current_window (actor);
159
98
        }
160
99
        else  // no more registrar on the bus.
161
100
        {
247
186
        DbusmenuGtkMenu *pMenu;
248
187
} CDSharedMemory;
249
188
 
250
 
static void _on_menu_destroyed (CairoDockModuleInstance *myApplet, GObject *old_menu_pointer)
 
189
static void _on_menu_destroyed (GldiModuleInstance *myApplet, GObject *old_menu_pointer)
251
190
{
252
191
        if (old_menu_pointer == (GObject*)myData.pMenu)
253
192
                myData.pMenu = NULL;
280
219
        CD_APPLET_LEAVE (TRUE);
281
220
}*/
282
221
 
283
 
static void _on_got_menu (DBusGProxy *proxy, DBusGProxyCall *call_id, CairoDockModuleInstance *myApplet)
 
222
static void _on_got_menu (DBusGProxy *proxy, DBusGProxyCall *call_id, GldiModuleInstance *myApplet)
284
223
{
285
224
        cd_debug ("%s ()", __func__);
286
225
        CD_APPLET_ENTER;
336
275
        ///g_free (cMenuObject);
337
276
        CD_APPLET_LEAVE ();
338
277
}
339
 
static void _get_application_menu (Window Xid)
 
278
static void _get_application_menu (GldiWindowActor *actor)
340
279
{
341
280
        // destroy the current menu
342
281
        if (myData.pMenu != NULL)
359
298
        }
360
299
        
361
300
        // get the new one.
362
 
        if (Xid != 0)
 
301
        if (actor != NULL)
363
302
        {
364
303
                if (myData.pProxyRegistrar != NULL)
365
304
                {
 
305
                        guint id = gldi_window_get_id (actor);
 
306
                        
366
307
                        s_pGetMenuCall = dbus_g_proxy_begin_call (myData.pProxyRegistrar,
367
308
                                "GetMenuForWindow",
368
309
                                (DBusGProxyCallNotify)_on_got_menu,
369
310
                                myApplet,
370
311
                                (GDestroyNotify) NULL,
371
 
                                G_TYPE_UINT, Xid,
 
312
                                G_TYPE_UINT, id,
372
313
                                G_TYPE_INVALID);
373
314
                }
374
315
        }
379
320
 /// START / STOP ///
380
321
////////////////////
381
322
 
382
 
static gboolean _get_current_window_idle (CairoDockModuleInstance *myApplet)
 
323
static gboolean _get_current_window_idle (GldiModuleInstance *myApplet)
383
324
{
384
325
        // get the controls and menu of the current window.
385
 
        Window iActiveWindow = cairo_dock_get_current_active_window ();
 
326
        GldiWindowActor *actor = gldi_windows_get_active ();
386
327
        
387
 
        cd_app_menu_set_current_window (iActiveWindow);
 
328
        cd_app_menu_set_current_window (actor);
388
329
        
389
330
        myData.iSidInitIdle = 0;
390
331
        return FALSE;
391
332
}
392
 
static gboolean _remove_windows_borders (CairoDockModuleInstance *myApplet)
 
333
static gboolean _remove_windows_borders_idle (GldiModuleInstance *myApplet)
393
334
{
394
335
        cd_app_menu_set_windows_borders (FALSE);
395
336
        
411
352
        // remove borders from all maximised windows
412
353
        if (myConfig.bDisplayControls)
413
354
        {
414
 
                myData.iSidInitIdle2 = g_idle_add ((GSourceFunc)_remove_windows_borders, myApplet);  // in idle, because it's heavy + the applications-manager is started after the plug-ins.
 
355
                myData.iSidInitIdle2 = g_idle_add ((GSourceFunc)_remove_windows_borders_idle, myApplet);  // in idle, because it's heavy + the applications-manager is started after the plug-ins.
415
356
        }
416
357
        
417
358
        if (myConfig.bDisplayControls)
439
380
                g_source_remove (myData.iSidInitIdle);
440
381
        if (myData.iSidInitIdle2 != 0)
441
382
                g_source_remove (myData.iSidInitIdle2);
 
383
        gldi_icon_unset_appli (myIcon);
442
384
}
443
385
 
444
386
 
445
 
void cd_app_menu_set_current_window (Window iActiveWindow)
 
387
void cd_app_menu_set_current_window (GldiWindowActor *actor)
446
388
{
447
 
        cd_debug ("%s (%ld)", __func__, iActiveWindow);
448
 
        if (iActiveWindow != myData.iCurrentWindow)
 
389
        cd_debug ("%s (%p)", __func__, actor);
 
390
        if (actor != myData.pCurrentWindow)
449
391
        {
450
 
                myData.iPreviousWindow = myData.iCurrentWindow;
451
 
                myData.iCurrentWindow = iActiveWindow;
452
 
                myIcon->Xid = iActiveWindow;  // set the Xid on our icon, so that the dock adds the usual actions in our right-click menu.
 
392
                myData.pPreviousWindow = myData.pCurrentWindow;
 
393
                myData.pCurrentWindow = actor;
 
394
                gldi_icon_set_appli (myIcon, actor);  // set the actor on our icon, so that the dock adds the usual actions in our right-click menu. // this takes a reference on the actor, and remove the ref on the previous one.
453
395
                
454
396
                if (myConfig.bDisplayMenu)
455
 
                        _get_application_menu (iActiveWindow);
 
397
                        _get_application_menu (actor);
456
398
                
457
399
                if (myConfig.bDisplayControls)
458
 
                        _get_window_allowed_actions (iActiveWindow);
 
400
                        _get_window_allowed_actions (actor);
459
401
                
460
402
                // update the icon
461
 
                Icon *icon = cairo_dock_get_icon_with_Xid (iActiveWindow);
462
 
                CD_APPLET_SET_NAME_FOR_MY_ICON (icon ? icon->cName : NULL);
 
403
                CD_APPLET_SET_NAME_FOR_MY_ICON (actor ? actor->cName : NULL);
463
404
                
464
405
                cd_app_menu_redraw_icon ();
465
406
        }