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
|
Only in src/: Makefile
diff -Pua src/Makefile.in fixed/Makefile.in
--- src/Makefile.in 2004-07-15 07:10:54.000000000 -0400
+++ fixed/Makefile.in 2005-09-18 08:19:39.000000000 -0400
@@ -17,9 +17,9 @@
PROG = Pager
-SRCS = choices.c gui_support.c main.c options.c rox_gettext.c
+SRCS = choices.c gui_support.c main.c options.c rox_gettext.c window-menu.c
-OBJECTS = choices.o gui_support.o main.o options.o rox_gettext.o
+OBJECTS = choices.o gui_support.o main.o options.o rox_gettext.o window-menu.o
############ Things to keep the same
Only in src/: choices.c
Only in src/: choices.h
diff -Pua src/config.h.in fixed/config.h.in
--- src/config.h.in 2004-07-15 07:10:54.000000000 -0400
+++ fixed/config.h.in 2005-09-18 08:19:52.000000000 -0400
@@ -2,6 +2,8 @@
#define PROJECT "Pager"
+#undef HAVE_WNCK_CREATE_WINDOW_MENU
+
#include "rox_gettext.h"
#define _(String) rox_gettext(String)
/* Short for gettext_noop() - marks a string as translatable without
Only in src/: configure
diff -Pua src/configure.in fixed/configure.in
--- src/configure.in 2003-07-16 06:38:38.000000000 -0400
+++ fixed/configure.in 2005-09-18 08:20:05.000000000 -0400
@@ -82,6 +82,12 @@
AC_C_CONST
AC_TYPE_SIZE_T
+dnl does libwnck have wnck_create_window_menu() ?
+ac_LIBS="$LIBS"
+LIBS="$LIBS `pkg-config --libs libwnck-1.0`"
+AC_CHECK_FUNCS(wnck_create_window_menu)
+LIBS="$ac_LIBS"
+
dnl Extract version info from AppInfo.xml
AC_MSG_CHECKING(extracting version information)
[
Only in src/: global.h
Only in src/: gui_support.c
Only in src/: gui_support.h
diff -Pua src/main.c fixed/main.c
--- src/main.c 2004-08-15 13:19:39.000000000 -0400
+++ fixed/main.c 2005-09-18 08:19:24.000000000 -0400
@@ -18,6 +18,8 @@
#include "options.h"
#include "choices.h"
+#include "window-menu.h"
+
char *app_dir = NULL;
static GdkWindow *socket = NULL; /* NULL => Not an applet */
@@ -28,6 +30,13 @@
static Option n_rows;
+static int
+workspace_at_point (WnckPager *pager,
+ int x,
+ int y,
+ int *viewport_x,
+ int *viewport_y);
+
/* Read the contents of this property. g_free() the result. */
static char *read_property(GdkWindow *window, GdkAtom prop,
GdkAtom type, gint *out_length)
@@ -169,14 +178,47 @@
return window_list;
}
+/* Returns a list of the windows on the active workspace */
+static GList *get_workspace_window_list(WnckWorkspace *work_space,
+ GList *wins)
+{
+ GList *window_list = NULL;
+ while (wins)
+ {
+ WnckWindow *window = WNCK_WINDOW(wins->data);
+ if (wnck_window_is_on_workspace(window,work_space))
+ window_list = g_list_append(window_list,wins->data);
+ wins = wins->next;
+ }
+ wins = g_list_first(wins);
+ return window_list;
+}
+
+/* Returns the selected workspace from the pager widget */
+static WnckWorkspace *get_selected_workspace(GdkEventButton *event)
+{
+ int space_number;
+
+ space_number = workspace_at_point(WNCK_PAGER(pager),
+ event->x, event->y,
+ NULL, NULL);
+ if (space_number == -1)
+ return wnck_screen_get_active_workspace(screen);
+
+ return wnck_screen_get_workspace(screen, space_number);
+}
+
static gboolean button_event(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
if (event->button == 3)
{
+ WnckWorkspace *work_space;
+ GtkWidget *menu_all;
GtkWidget *menu;
GtkWidget *item;
+ GList *wins_all;
GList *wins;
gchar *pos = NULL;
@@ -186,12 +228,28 @@
gdk_atom_intern("_ROX_PANEL_MENU_POS",
FALSE));
}
-
- wins = get_window_list();
+ wins_all = get_window_list();
+#ifdef HAVE_WNCK_CREATE_WINDOW_MENU
+ menu_all = wnck_create_window_menu(wins_all);
+#else
+ menu_all = our_create_window_menu(wins_all);
+#endif
+
+ work_space = get_selected_workspace(event);
+ wins = get_workspace_window_list(work_space,wins_all);
+#ifdef HAVE_WNCK_CREATE_WINDOW_MENU
menu = wnck_create_window_menu(wins);
+#else
+ menu = our_create_window_menu(wins);
+#endif
item = gtk_menu_item_new();
+
+ item = gtk_menu_item_new_with_label(_("All windows"));
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu_all);
+ gtk_widget_show(item);
+
gtk_menu_append(GTK_MENU(menu), item);
gtk_widget_show(item);
@@ -260,8 +318,7 @@
{
double aspect;
Orient orient = panel_get_orient();
- int n_screens = wnck_screen_get_workspace_count(
- wnck_screen_get_default());
+ int n_screens = wnck_screen_get_workspace_count(screen);
*width = alloc_width;
*height = alloc_height;
@@ -467,3 +524,175 @@
return 0;
}
+
+/* Taken from libwnck/pager.c */
+#define POINT_IN_RECT(xcoord, ycoord, rect) \
+ ((xcoord) >= (rect).x && \
+ (xcoord) < ((rect).x + (rect).width) && \
+ (ycoord) >= (rect).y && \
+ (ycoord) < ((rect).y + (rect).height))
+
+#define N_SCREEN_CONNECTIONS 11
+
+static void
+get_workspace_rect (WnckPager *pager,
+ int space,
+ GdkRectangle *rect)
+{
+ int hsize, vsize;
+ int n_spaces;
+ int spaces_per_row;
+ GtkWidget *widget;
+ int col, row;
+ int focus_width;
+ int nrows = n_rows.int_value;
+
+ gtk_widget_style_get (GTK_WIDGET (pager),
+ "focus-line-width", &focus_width,
+ NULL);
+
+ widget = GTK_WIDGET (pager);
+
+ hsize = widget->allocation.width - 2 * focus_width;
+ vsize = widget->allocation.height - 2 * focus_width;
+
+ /* if (pager->priv->shadow_type != GTK_SHADOW_NONE) */
+ {
+ hsize -= 2 * widget->style->xthickness;
+ vsize -= 2 * widget->style->ythickness;
+ }
+
+ n_spaces = wnck_screen_get_workspace_count (wnck_screen_get_default ());
+
+ g_return_if_fail(nrows > 0);
+ spaces_per_row = (n_spaces + nrows - 1) / nrows;
+
+ if (panel_get_orient() == ORIENT_VERT)
+ {
+ rect->width = (hsize - (nrows - 1)) / nrows;
+ rect->height = (vsize - (spaces_per_row - 1)) / spaces_per_row;
+
+ col = space / spaces_per_row;
+ row = space % spaces_per_row;
+ rect->x = (rect->width + 1) * col;
+ rect->y = (rect->height + 1) * row;
+
+ if (col == nrows - 1)
+ rect->width = hsize - rect->x;
+
+ if (row == spaces_per_row - 1)
+ rect->height = vsize - rect->y;
+ }
+ else
+ {
+ rect->width = (hsize - (spaces_per_row - 1)) / spaces_per_row;
+ rect->height = (vsize - (nrows - 1)) / nrows;
+
+ col = space % spaces_per_row;
+ row = space / spaces_per_row;
+ rect->x = (rect->width + 1) * col;
+ rect->y = (rect->height + 1) * row;
+
+ if (col == spaces_per_row - 1)
+ rect->width = hsize - rect->x;
+
+ if (row == nrows - 1)
+ rect->height = vsize - rect->y;
+ }
+
+ rect->x += focus_width;
+ rect->y += focus_width;
+
+ /* if (pager->priv->shadow_type != GTK_SHADOW_NONE) */
+ {
+ rect->x += widget->style->xthickness;
+ rect->y += widget->style->ythickness;
+ }
+}
+
+static int
+workspace_at_point (WnckPager *pager,
+ int x,
+ int y,
+ int *viewport_x,
+ int *viewport_y)
+{
+ GtkWidget *widget;
+ int i;
+ int n_spaces;
+ int focus_width;
+ int xthickness;
+ int ythickness;
+
+ widget = GTK_WIDGET (pager);
+
+ gtk_widget_style_get (GTK_WIDGET (pager),
+ "focus-line-width", &focus_width,
+ NULL);
+
+ xthickness = focus_width + widget->style->xthickness;
+ ythickness = focus_width + widget->style->ythickness;
+
+ n_spaces = wnck_screen_get_workspace_count (screen);
+
+ i = 0;
+ while (i < n_spaces)
+ {
+ GdkRectangle rect;
+
+ get_workspace_rect (pager, i, &rect);
+
+ /* if (pager->priv->shadow_type != GTK_SHADOW_NONE) */
+ {
+ /* If workspace is on the edge, pretend points on the frame
+ * belong to the workspace.
+ */
+
+ GtkWidget *widget = GTK_WIDGET (pager);
+
+ if (rect.x == xthickness)
+ {
+ rect.x = 0;
+ rect.width += xthickness;
+ }
+ if (rect.y == ythickness)
+ {
+ rect.y = 0;
+ rect.height += ythickness;
+ }
+ if (rect.y + rect.height == widget->allocation.height - ythickness)
+ {
+ rect.height += ythickness;
+ }
+ if (rect.x + rect.width == widget->allocation.width - xthickness)
+ {
+ rect.width += xthickness;
+ }
+ }
+
+ if (POINT_IN_RECT (x, y, rect))
+ {
+ double width_ratio, height_ratio;
+ WnckWorkspace *space;
+
+ space = wnck_screen_get_workspace (screen, i);
+ g_assert (space != NULL);
+
+ /* Scale x, y mouse coords to corresponding screenwide viewport coords */
+
+ width_ratio = (double) wnck_workspace_get_width (space) / (double) rect.width;
+ height_ratio = (double) wnck_workspace_get_height (space) / (double) rect.height;
+
+ if (viewport_x)
+ *viewport_x = width_ratio * (x - rect.x);
+ if (viewport_y)
+ *viewport_y = height_ratio * (y - rect.y);
+
+ return i;
+ }
+
+ ++i;
+ }
+
+ return -1;
+}
Only in src/: options.c
Only in src/: options.h
Only in src/: po
Only in src/: rox_gettext.c
Only in src/: rox_gettext.h
diff -Pua src/window-menu.c fixed/window-menu.c
--- src/window-menu.c 1969-12-31 19:00:00.000000000 -0500
+++ fixed/window-menu.c 2005-09-18 08:20:16.000000000 -0400
@@ -0,0 +1,137 @@
+/* window menu */
+
+/*
+ * Copyright (C) 2001 Havoc Pennington
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* Modified by Lucas Hazel and Stephen Watson for use in the Pager
+ * application because it was removed from later libwnck versions
+ */
+
+#include "config.h"
+#ifndef HAVE_WNCK_CREATE_WINDOW_MENU
+
+#include "window-menu.h"
+
+static void object_weak_notify (gpointer data,
+ GObject *obj);
+static void window_weak_notify (gpointer data,
+ GObject *window);
+
+static void
+window_weak_notify (gpointer data,
+ GObject *window)
+{
+ g_object_set_data (G_OBJECT (data), "wnck-window-data", NULL);
+ g_object_weak_unref (G_OBJECT (data),
+ object_weak_notify,
+ window);
+}
+
+static void
+set_window (GObject *obj,
+ WnckWindow *win)
+{
+ g_object_set_data (obj, "wnck-window-data", win);
+ if (win)
+ {
+ g_object_weak_ref (G_OBJECT (win), window_weak_notify, obj);
+ g_object_weak_ref (obj, object_weak_notify, win);
+ }
+}
+
+static void
+object_weak_notify (gpointer data,
+ GObject *obj)
+{
+ g_object_weak_unref (G_OBJECT (data),
+ window_weak_notify,
+ obj);
+}
+
+static WnckWindow*
+get_window (GObject *obj)
+{
+ return g_object_get_data (obj, "wnck-window-data");
+}
+
+static void
+item_activated_callback (GtkWidget *menu_item,
+ gpointer data)
+{
+ WnckWindow *win;
+
+ win = get_window (G_OBJECT (menu_item));
+
+ if (win == NULL)
+ return;
+
+ wnck_window_activate (win, 0);
+}
+
+GtkWidget*
+our_create_window_menu (GList *windows)
+{
+ GList *tmp;
+ GtkWidget *menu;
+
+ menu = gtk_menu_new ();
+
+ tmp = windows;
+
+ while (tmp != NULL)
+ {
+ WnckWindow *win = WNCK_WINDOW (tmp->data);
+ GdkPixbuf *icon;
+ const char *title;
+ GtkWidget *mi;
+
+ icon = wnck_window_get_icon (win);
+ title = wnck_window_get_icon_name (win);
+
+ if (icon)
+ {
+ GtkWidget *image;
+
+ image = gtk_image_new_from_pixbuf (icon);
+
+ mi = gtk_image_menu_item_new_with_label (title);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi),
+ image);
+ }
+ else
+ {
+ mi = gtk_menu_item_new_with_label (title);
+ }
+
+ g_signal_connect (G_OBJECT (mi), "activate",
+ G_CALLBACK (item_activated_callback), NULL);
+
+ set_window (G_OBJECT (mi), win);
+
+ gtk_widget_show (mi);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
+ tmp = tmp->next;
+ }
+
+ return menu;
+}
+
+#endif /* HAVE_WNCK_CREATE_WINDOW_MENU */
diff -Pua src/window-menu.h fixed/window-menu.h
--- src/window-menu.h 1969-12-31 19:00:00.000000000 -0500
+++ fixed/window-menu.h 2005-09-18 08:20:27.000000000 -0400
@@ -0,0 +1,14 @@
+#ifndef HAVE_WNCK_CREATE_WINDOW_MENU
+
+#ifndef WINDOW_MENU_H
+#define WINDOW_MENU_H
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+
+#include <libwnck/libwnck.h>
+
+extern GtkWidget* our_create_window_menu (GList *windows);
+
+#endif /* WINDOW_MENU_H */
+
+#endif /* HAVE_WNCK_CREATE_WINDOW_MENU */
|