~laney/bamf/prefix-regex-python

« back to all changes in this revision

Viewing changes to src/bamf-legacy-screen.c

  • Committer: Tarmac
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2014-02-14 03:12:52 UTC
  • mfrom: (590.1.2 window-action-menu)
  • Revision ID: tarmac-20140214031252-vjnxndq3rv3vbszg
BamfLegacyScreen: When in Unity monitor for compiz ClientMessage's to show action menu

If we get a _COMPIZ_TOOLKIT_ACTION client message with the internal value
_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU, then we are requested by compiz
to show the window action menu, and thus let's ask the proper BamfLegacyWindow
to do that, thanks to libwnck. Fixes: https://bugs.launchpad.net/bugs/1280042.

Approved by Brandon Schaefer, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "bamf-legacy-screen.h"
21
21
#include "bamf-legacy-screen-private.h"
 
22
#include <gdk/gdkx.h>
22
23
#include <gio/gio.h>
23
24
 
24
25
G_DEFINE_TYPE (BamfLegacyScreen, bamf_legacy_screen, G_TYPE_OBJECT);
38
39
};
39
40
 
40
41
static guint legacy_screen_signals[LAST_SIGNAL] = { 0 };
 
42
static Atom _COMPIZ_TOOLKIT_ACTION = 0;
 
43
static Atom _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = 0;
41
44
 
42
45
struct _BamfLegacyScreenPrivate
43
46
{
350
353
  return NULL;
351
354
}
352
355
 
 
356
static BamfLegacyWindow *
 
357
bamf_legacy_screen_get_window_by_xid (BamfLegacyScreen *screen, Window xid)
 
358
{
 
359
  BamfLegacyWindow *window;
 
360
  GList *l;
 
361
 
 
362
  g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (screen), NULL);
 
363
 
 
364
  for (l = screen->priv->windows; l; l = l->next)
 
365
    {
 
366
      window = l->data;
 
367
 
 
368
      if (bamf_legacy_window_get_xid (window) == xid)
 
369
        return window;
 
370
    }
 
371
 
 
372
  return NULL;
 
373
}
 
374
 
353
375
static void
354
376
handle_active_window_changed (WnckScreen *screen, WnckWindow *previous, BamfLegacyScreen *self)
355
377
{
428
450
                  G_TYPE_NONE, 0);
429
451
}
430
452
 
 
453
#include <gdk/gdkx.h>
 
454
 
 
455
GdkFilterReturn filter_compiz_messages(GdkXEvent *gdkxevent, GdkEvent *event, gpointer data)
 
456
{
 
457
  BamfLegacyScreen *self = data;
 
458
  BamfLegacyWindow *window;
 
459
  XEvent *xevent = gdkxevent;
 
460
 
 
461
  if (xevent->type == ClientMessage)
 
462
    {
 
463
      if (xevent->xclient.message_type == _COMPIZ_TOOLKIT_ACTION)
 
464
        {
 
465
          Atom msg = xevent->xclient.data.l[0];
 
466
 
 
467
          if (msg == _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU)
 
468
            {
 
469
              window = bamf_legacy_screen_get_window_by_xid (self, xevent->xany.window);
 
470
 
 
471
              if (BAMF_IS_LEGACY_WINDOW (window))
 
472
                {
 
473
                  Time time = xevent->xclient.data.l[1];
 
474
                  int button = xevent->xclient.data.l[2];
 
475
                  int x = xevent->xclient.data.l[3];
 
476
                  int y = xevent->xclient.data.l[4];
 
477
 
 
478
                  bamf_legacy_window_show_action_menu (window, time, button, x, y);
 
479
 
 
480
                  return GDK_FILTER_REMOVE;
 
481
                }
 
482
            }
 
483
        }
 
484
    }
 
485
 
 
486
  return GDK_FILTER_CONTINUE;
 
487
}
 
488
 
431
489
BamfLegacyScreen *
432
490
bamf_legacy_screen_get_default ()
433
491
{
456
514
  g_signal_connect (G_OBJECT (self->priv->legacy_screen), "active-window-changed",
457
515
                    (GCallback) handle_active_window_changed, self);
458
516
 
 
517
  if (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0)
 
518
    {
 
519
      Display *dpy = gdk_x11_get_default_xdisplay ();
 
520
      _COMPIZ_TOOLKIT_ACTION = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION", False);
 
521
      _COMPIZ_TOOLKIT_ACTION_WINDOW_MENU = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", False);
 
522
      gdk_window_add_filter (NULL, filter_compiz_messages, self);
 
523
    }
 
524
 
459
525
  return static_screen;
460
526
}
461
527