summaryrefslogtreecommitdiff
path: root/src/menu.c
blob: e7bc7f1cdb9e49e9b673954a513dec38057ce86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/* Metacity window menu */

/* 
 * Copyright (C) 2001 Havoc Pennington
 * Copyright (C) 2004 Rob Adams
 * Copyright (C) 2005 Elijah Newren
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#include <config.h>
#include <stdio.h>
#include <string.h>
#include "menu.h"
#include "main.h"
#include "util.h"
#include "core.h"
#include "themewidget.h"
#include "metaaccellabel.h"
#include "ui.h"

typedef struct _MenuItem MenuItem;
typedef struct _MenuData MenuData;

typedef enum
{
  MENU_ITEM_SEPARATOR = 0,
  MENU_ITEM_NORMAL,
  MENU_ITEM_IMAGE,
  MENU_ITEM_CHECKBOX,
  MENU_ITEM_RADIOBUTTON,
} MetaMenuItemType;

struct _MenuItem
{
  MetaMenuOp op;
  MetaMenuItemType type;
  const char *stock_id;
  const gboolean checked;
  const char *label;
};


struct _MenuData
{
  MetaWindowMenu *menu;
  MetaMenuOp op;
};

static void activate_cb (GtkWidget *menuitem, gpointer data);

static MenuItem menuitems[] = {
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MINIMIZE, MENU_ITEM_IMAGE, METACITY_STOCK_MINIMIZE, FALSE, N_("Mi_nimize") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MAXIMIZE, MENU_ITEM_IMAGE, METACITY_STOCK_MAXIMIZE, FALSE, N_("Ma_ximize") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_UNMAXIMIZE, MENU_ITEM_NORMAL, NULL, FALSE, N_("Unma_ximize") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_SHADE, MENU_ITEM_NORMAL, NULL, FALSE, N_("Roll _Up") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_UNSHADE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Unroll") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MOVE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Move") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_RESIZE, MENU_ITEM_NORMAL, NULL, FALSE, N_("_Resize") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_RECOVER, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move Titlebar On_screen") },
  { 0, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL }, /* separator */
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_DELETE, MENU_ITEM_IMAGE, METACITY_STOCK_DELETE, FALSE, N_("_Close") },
  { META_MENU_OP_WORKSPACES, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL }, /* separator */
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_ABOVE, MENU_ITEM_CHECKBOX, NULL, FALSE, N_("Always on _Top") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_UNABOVE, MENU_ITEM_CHECKBOX, NULL, TRUE, N_("Always on _Top") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_STICK, MENU_ITEM_RADIOBUTTON, NULL, FALSE, N_("_Always on Visible Workspace") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_UNSTICK, MENU_ITEM_RADIOBUTTON, NULL, FALSE,  N_("_Only on This Workspace") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MOVE_LEFT, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Left") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MOVE_RIGHT, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace R_ight") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MOVE_UP, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Up") },
  /* Translators: Translate this string the same way as you do in libwnck! */
  { META_MENU_OP_MOVE_DOWN, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Workspace _Down") }
};

static void
popup_position_func (GtkMenu   *menu,
                     gint      *x,
                     gint      *y,
                     gboolean  *push_in,
                     gpointer  user_data)
{
  GtkRequisition req;      
  GdkPoint *pos;

  pos = user_data;
  
  gtk_widget_size_request (GTK_WIDGET (menu), &req);

  *x = pos->x;
  *y = pos->y;
  
  if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
    *x = MAX (0, *x - req.width); 

  /* Ensure onscreen */
  *x = CLAMP (*x, 0, MAX (0, gdk_screen_width () - req.width));
  *y = CLAMP (*y, 0, MAX (0, gdk_screen_height () - req.height));
}

static void
menu_closed (GtkMenu *widget,
             gpointer data)
{
  MetaWindowMenu *menu;
  
  menu = data;

  meta_frames_notify_menu_hide (menu->frames);
#ifdef MPX
  (* menu->func) (menu, gdk_display,
                  menu->client_xwindow,
                  gtk_get_current_event_time (),
                  0, 0, 0,
                  menu->data);

#else
  (* menu->func) (menu, gdk_display,
                  menu->client_xwindow,
                  gtk_get_current_event_time (),
                  0, 0,
                  menu->data);
#endif
  
  /* menu may now be freed */
}

static void
activate_cb (GtkWidget *menuitem, gpointer data)
{
  MenuData *md;
  
  g_return_if_fail (GTK_IS_WIDGET (menuitem));
  
  md = data;

  meta_frames_notify_menu_hide (md->menu->frames);
#ifdef MPX
  (* md->menu->func) (md->menu, gdk_display,
                      md->menu->client_xwindow,
                      gtk_get_current_event_time (),
                      md->op,
                      GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
                                                          "workspace")),
		      g_object_get_data (G_OBJECT (menuitem), "device"),
                      md->menu->data);

#else
  (* md->menu->func) (md->menu, gdk_display,
                      md->menu->client_xwindow,
                      gtk_get_current_event_time (),
                      md->op,
                      GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem),
                                                          "workspace")),
                      md->menu->data);
#endif

  /* menu may now be freed */
}

/*
 * Given a Display and an index, get the workspace name and add any
 * accelerators. At the moment this means adding a _ if the name is of
 * the form "Workspace n" where n is less than 10, and escaping any
 * other '_'s so they do not create inadvertant accelerators.
 * 
 * The calling code owns the string, and is reponsible to free the
 * memory after use.
 */
static char*
get_workspace_name_with_accel (Display *display,
                               Window   xroot,
                               int      index)
{
  const char *name;
  int number;

  name = meta_core_get_workspace_name_with_index (display, xroot, index);

  g_assert (name != NULL);
  
  /*
   * If the name is of the form "Workspace x" where x is an unsigned
   * integer, insert a '_' before the number if it is less than 10 and
   * return it
   */
  number = 0;
  if (sscanf (name, _("Workspace %d"), &number) == 1)
    {
      char *new_name;
      
      /*
       * Above name is a pointer into the Workspace struct. Here we make
       * a copy copy so we can have our wicked way with it.
       */
      if (number == 10)
        new_name = g_strdup_printf (_("Workspace 1_0"));
      else
        new_name = g_strdup_printf (_("Workspace %s%d"),
                                    number < 10 ? "_" : "",
                                    number);
      return new_name;
    }
  else
    {
      /*
       * Otherwise this is just a normal name. Escape any _ characters so that
       * the user's workspace names do not get mangled.  If the number is less
       * than 10 we provide an accelerator.
       */
      char *new_name;
      const char *source;
      char *dest;

      /*
       * Assume the worst case, that every character is a _.  We also
       * provide memory for " (_#)"
       */
      new_name = g_malloc0 (strlen (name) * 2 + 6 + 1);

      /*
       * Now iterate down the strings, adding '_' to escape as we go
       */
      dest = new_name;
      source = name;
      while (*source != '\0')
        {
          if (*source == '_')
            *dest++ = '_';
          *dest++ = *source++;
        }

      /* People don't start at workstation 0, but workstation 1 */
      if (index < 9)
        {
          g_snprintf (dest, 6, " (_%d)", index + 1);
        }
      else if (index == 9)
        {
          g_snprintf (dest, 6, " (_0)");
        }

      return new_name;
    }
}

static GtkWidget *
menu_item_new (MenuItem *menuitem, int workspace_id)
{
  unsigned int key;
  MetaVirtualModifier mods;
  const char *i18n_label;
  GtkWidget *mi;
  GtkWidget *accel_label;

  if (menuitem->type == MENU_ITEM_NORMAL)
    {
      mi = gtk_menu_item_new ();
    }
  else if (menuitem->type == MENU_ITEM_IMAGE)
    {
      GtkWidget *image;
      
      image = gtk_image_new_from_stock (menuitem->stock_id, GTK_ICON_SIZE_MENU);
      mi = gtk_image_menu_item_new ();
     
      gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), image);
      gtk_widget_show (image);
    }
  else if (menuitem->type == MENU_ITEM_CHECKBOX)
    {
      mi = gtk_check_menu_item_new ();
      
      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                      menuitem->checked);
    }    
  else if (menuitem->type == MENU_ITEM_RADIOBUTTON)
    {
      mi = gtk_check_menu_item_new ();

      gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (mi),
                                             TRUE);
      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                      menuitem->checked);
    }
  else
    return gtk_separator_menu_item_new ();

  i18n_label = _(menuitem->label);
  meta_core_get_menu_accelerator (menuitem->op, workspace_id, &key, &mods);

  accel_label = meta_accel_label_new_with_mnemonic (i18n_label);
  gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);

  gtk_container_add (GTK_CONTAINER (mi), accel_label);
  gtk_widget_show (accel_label);

  meta_accel_label_set_accelerator (META_ACCEL_LABEL (accel_label),
                                    key, mods);
  
  return mi;
}

MetaWindowMenu*
#ifdef MPX
meta_window_menu_new   (MetaFrames         *frames,
                        MetaMenuOp          ops,
                        MetaMenuOp          insensitive,
			MetaDevices	   *devices,
                        Window              client_xwindow,
                        unsigned long       active_workspace,
                        int                 n_workspaces,
                        MetaWindowMenuFunc  func,
                        gpointer            data)
#else
meta_window_menu_new   (MetaFrames         *frames,
                        MetaMenuOp          ops,
                        MetaMenuOp          insensitive,
                        Window              client_xwindow,
                        unsigned long       active_workspace,
                        int                 n_workspaces,
                        MetaWindowMenuFunc  func,
                        gpointer            data)
#endif
{
  int i;
  MetaWindowMenu *menu;

  /* FIXME: Modifications to 'ops' should happen in meta_window_show_menu */
  if (n_workspaces < 2)
    ops &= ~(META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES);
  else if (n_workspaces == 2) 
    /* #151183: If we only have two workspaces, disable the menu listing them. */
    ops &= ~(META_MENU_OP_WORKSPACES);
  
  menu = g_new (MetaWindowMenu, 1);
  menu->frames = frames;
  menu->client_xwindow = client_xwindow;
  menu->func = func;
  menu->data = data;
  menu->ops = ops;
  menu->insensitive = insensitive;  
  
  menu->menu = gtk_menu_new ();

  gtk_menu_set_screen (GTK_MENU (menu->menu),
                       gtk_widget_get_screen (GTK_WIDGET (frames)));

  for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++)
    {
      MenuItem menuitem = menuitems[i];
      if (ops & menuitem.op || menuitem.op == 0)
        {
          GtkWidget *mi;
          MenuData *md;
          unsigned int key;
          MetaVirtualModifier mods;

          mi = menu_item_new (&menuitem, -1);

          /* Set the activeness of radiobuttons. */
          switch (menuitem.op)
            {
            case META_MENU_OP_STICK:
              gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                              active_workspace == 0xFFFFFFFF);
              break;
            case META_MENU_OP_UNSTICK:
              gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                                              active_workspace != 0xFFFFFFFF);
              break;
            default:
              break;
            }

          if (menuitem.type != MENU_ITEM_SEPARATOR)
            {
              meta_core_get_menu_accelerator (menuitems[i].op, -1,
                                              &key, &mods);

              if (insensitive & menuitem.op)
                gtk_widget_set_sensitive (mi, FALSE);
              
              md = g_new (MenuData, 1);
              
              md->menu = menu;
              md->op = menuitem.op;
              
              gtk_signal_connect_full (GTK_OBJECT (mi),
                                       "activate",
                                       GTK_SIGNAL_FUNC (activate_cb),
                                       NULL,
                                       md,
                                       g_free, FALSE, FALSE);
            }
          
          gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi);
          
          gtk_widget_show (mi);
        }
    }

  if (ops & META_MENU_OP_WORKSPACES)
    {
      Display *display;
      Window xroot;
      GdkScreen *screen;
      GtkWidget *submenu;
      GtkWidget *submenuitem;

      MenuItem to_another_workspace = {
        0, MENU_ITEM_NORMAL,
        NULL, FALSE,
        N_("Move to Another _Workspace")
      };

      meta_verbose ("Creating %d-workspace menu current space %lu\n",
                    n_workspaces, active_workspace);
          
      display = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window);
        
      screen = gdk_drawable_get_screen (GTK_WIDGET (frames)->window);
      xroot = GDK_DRAWABLE_XID (gdk_screen_get_root_window (screen));

      submenu = gtk_menu_new ();
      submenuitem = menu_item_new (&to_another_workspace, -1);
      gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), submenuitem);
      gtk_widget_show (submenuitem);
           
      for (i = 0; i < n_workspaces; i++)
        {
          char *label;
          MenuData *md;
          unsigned int key;
          MetaVirtualModifier mods;
          MenuItem moveitem;
          GtkWidget *mi;
          
          meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES,
                                          i + 1,
                                          &key, &mods);
              
          label = get_workspace_name_with_accel (display, xroot, i);

          moveitem.type = MENU_ITEM_NORMAL;
          moveitem.op = META_MENU_OP_WORKSPACES;
          moveitem.label = label;
          mi = menu_item_new (&moveitem, i + 1);

          g_free (label);

          if ((active_workspace == (unsigned)i) && (ops & META_MENU_OP_UNSTICK))
            gtk_widget_set_sensitive (mi, FALSE);
            
          md = g_new (MenuData, 1);

          md->menu = menu;
          md->op = META_MENU_OP_WORKSPACES;

          g_object_set_data (G_OBJECT (mi),
                             "workspace",
                             GINT_TO_POINTER (i));
          
          gtk_signal_connect_full (GTK_OBJECT (mi),
                                   "activate",
                                   GTK_SIGNAL_FUNC (activate_cb),
                                   NULL,
                                   md,
                                   g_free, FALSE, FALSE);

          gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
          
          gtk_widget_show (mi);
        }
    }
  else
    meta_verbose ("not creating workspace menu\n");
  
  g_signal_connect (menu->menu, "selection_done",
                    G_CALLBACK (menu_closed), menu);  

#ifdef MPX

  {
    GtkWidget *mi;
    MenuItem sep = { 0, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL };
    mi = menu_item_new(&sep, -1);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi);
    gtk_widget_show (mi);
  }

  {
    /* SetClientPointer menu */

    Display *display;

    GtkWidget *submenu;
    GtkWidget *submenuitem;
    XID clientPtr;

    MenuItem select_client_pointer = {
      0, MENU_ITEM_NORMAL, NULL,
      FALSE, N_("Client pointer")
    };

    submenu = gtk_menu_new ();
    submenuitem = menu_item_new (&select_client_pointer, -1);
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), submenuitem);
    gtk_widget_show (submenuitem);

    display = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window);

    /* Someone might have changed the clientPointer! */
    XGetClientPointer(display, client_xwindow, &clientPtr);

    for (i = 0; i < devices->miceUsed; i++)
      {

        MenuItem setcpitem;
        MenuData *md;
        GtkWidget *mi;

        setcpitem.type = MENU_ITEM_RADIOBUTTON;
        setcpitem.op = META_MENU_OP_CLIENT_POINTER;
        setcpitem.label = devices->mice[i].name;
        mi = menu_item_new (&setcpitem, i+1);
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi),
                       (clientPtr == devices->mice[i].xdev->device_id) ? 1 : 0);

        md = g_new (MenuData, 1);
        md->menu = menu;
        md->op = META_MENU_OP_CLIENT_POINTER;
        g_object_set_data (G_OBJECT(mi),
                           "device",
                           &devices->mice[i]);
        gtk_signal_connect_full (GTK_OBJECT (mi),
                                 "activate",
                                 GTK_SIGNAL_FUNC (activate_cb),
                                 NULL,
                                 md,
                                 g_free, FALSE, FALSE);

        gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
        gtk_widget_show (mi);
      }
  }

  {
    /* Enable devices menu */
    Display *display;

    GtkWidget *submenu;
    GtkWidget *submenuitem;

    int rule, nperm, ndeny, j;
    XID *perm, *deny;

    int allowed;

    MenuItem allowed_devices = {
      0, MENU_ITEM_NORMAL, NULL,
      FALSE, N_("Allowed devices")
    };

    submenu = gtk_menu_new ();
    submenuitem = menu_item_new (&allowed_devices, -1);
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (submenuitem), submenu);
    gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), submenuitem);
    gtk_widget_show (submenuitem);

    display = gdk_x11_drawable_get_xdisplay (GTK_WIDGET (frames)->window);

    /* Gotta know which device has access to the window... Currently, we're
     * doing this by calling XQueryWindowAccess everytime. But maybe we could
     * store information on the windows. The problem is that if a client makes a
     * change, we won't be able to discover (will we? do we have an xevent for
     * it?) */
    XQueryWindowAccess(display, client_xwindow, &rule, &perm, &nperm, 
                       &deny, &ndeny);

    for (i = 0; i < devices->miceUsed; i++)
      {

        /* Add the mice to the menu */
        MenuItem alwdevitem;
        MenuData *md;
        GtkWidget *mi;

        alwdevitem.type = MENU_ITEM_CHECKBOX;
        alwdevitem.op = META_MENU_OP_ALLOW_ACCESS;
        alwdevitem.label = devices->mice[i].name;
        mi = menu_item_new (&alwdevitem, i+1);
	allowed = 1;
	for (j = 0; j < ndeny; j++)
	  if (devices->mice[i].xdev->device_id == deny[j] )
	    allowed = 0;
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), allowed);

        md = g_new (MenuData, 1);
        md->menu = menu;
        md->op = META_MENU_OP_ALLOW_ACCESS;
        g_object_set_data (G_OBJECT(mi),
                           "device",
                           &devices->mice[i]);
        gtk_signal_connect_full (GTK_OBJECT (mi),
                                 "activate",
                                 GTK_SIGNAL_FUNC (activate_cb),
                                 NULL,
                                 md,
                                 g_free, FALSE, FALSE);

        gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
        gtk_widget_show (mi);

      }


    /* Add a separator */
    {
      GtkWidget *mi;
      MenuItem sep = { 0, MENU_ITEM_SEPARATOR, NULL, FALSE, NULL };
      mi = menu_item_new(&sep, -1);
      gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
      gtk_widget_show (mi);
    }

    for (i = 0; i < devices->keybsUsed; i++)
      {

        /* Add the keyboards to the menu */
        MenuItem alwdevitem;
        MenuData *md;
        GtkWidget *mi;

        alwdevitem.type = MENU_ITEM_CHECKBOX;
        alwdevitem.op = META_MENU_OP_ALLOW_ACCESS;
        alwdevitem.label = devices->keyboards[i].name;
        mi = menu_item_new (&alwdevitem, i+1);

	allowed = 1;
	for (j = 0; j < ndeny; j++)
	  if (devices->keyboards[i].xdev->device_id == deny[j] )
	    allowed = 0;
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), allowed);

        md = g_new (MenuData, 1);
        md->menu = menu;
        md->op = META_MENU_OP_ALLOW_ACCESS;
        g_object_set_data (G_OBJECT(mi),
                           "device",
                           &devices->keyboards[i]);
        gtk_signal_connect_full (GTK_OBJECT (mi),
                                 "activate",
                                 GTK_SIGNAL_FUNC (activate_cb),
                                 NULL,
                                 md,
                                 g_free, FALSE, FALSE);

        gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
        gtk_widget_show (mi);

      }
      XFree(perm);
      XFree(deny);

  }

#endif

  return menu;
}

void
meta_window_menu_popup (MetaWindowMenu     *menu,
                        int                 root_x,
                        int                 root_y,
                        int                 button,
                        guint32             timestamp)
{
  GdkPoint *pt;
  
  pt = g_new (GdkPoint, 1);

  g_object_set_data_full (G_OBJECT (menu->menu),
                          "destroy-point",
                          pt,
                          g_free);

  pt->x = root_x;
  pt->y = root_y;
  
  gtk_menu_popup (GTK_MENU (menu->menu),
                  NULL, NULL,
                  popup_position_func, pt,
                  button,
                  timestamp);

  if (!GTK_MENU_SHELL (menu->menu)->have_xgrab)
    meta_warning ("GtkMenu failed to grab the pointer\n");
}

void
meta_window_menu_free (MetaWindowMenu *menu)
{
  gtk_widget_destroy (menu->menu);
  g_free (menu);
}