1 /*
2 * deskmenu - deskmenu.c
3 *
4 * Copyright (C) 2001 Ken Lynch
5 * Copyright (C) 2002 Stefan Pfetzing
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 #include "deskmenu.h"
23
24 void
raise_window(GtkWidget * widget,Window win)25 raise_window (GtkWidget * widget, Window win)
26 {
27 #ifdef DEBUG
28 printf ("raise_window\n");
29 #endif
30
31 XMapRaised (dpy, win);
32 XSetInputFocus (dpy, win, RevertToPointerRoot, CurrentTime);
33 }
34
35 char *
get_icon_name(Window win)36 get_icon_name (Window win)
37 {
38 XTextProperty text_prop;
39 int status;
40 char *iconname;
41
42 status = XGetWMIconName (dpy, win, &text_prop);
43 if (!status || !text_prop.value || !text_prop.nitems)
44 return NULL;
45 if (text_prop.encoding == XA_STRING)
46 {
47 if (!text_prop.value)
48 return NULL;
49 iconname = (char *) strdup (text_prop.value);
50 XFree (text_prop.value);
51 return iconname;
52 }
53 else
54 {
55 char **list;
56 int num;
57 XmbTextPropertyToTextList (dpy, &text_prop, &list, &num);
58 if (!num || !*list)
59 return NULL;
60 XFree (text_prop.value);
61 iconname = (char *) strdup (*list);
62 XFreeStringList (list);
63 return iconname;
64 }
65 }
66
67 void
add_windows_menu(GtkMenu * menu,char * title)68 add_windows_menu (GtkMenu * menu, char *title)
69 {
70 GtkWidget *menu_item, *win_menu;
71 Atom real_type;
72 int real_format;
73 unsigned long items_read, items_left, item = 0;
74 long *win = NULL;
75 char *name = NULL, label[27];
76
77 #ifdef DEBUG
78 printf ("add_windows_menu\n");
79 #endif
80
81 win_menu = gtk_menu_new ();
82 menu_item = add_menu_item (GTK_MENU (menu), title, NULL, NULL);
83
84 while (XGetWindowProperty
85 (dpy, root, gnome[WIN_CLIENT_LIST], item++, 1L, False, XA_CARDINAL,
86 &real_type, &real_format, &items_read, &items_left,
87 (unsigned char **) &win) == Success && items_read)
88 {
89 if (!(get_gnome_hint (*win, WIN_HINTS) & WIN_HINTS_SKIP_WINLIST)
90 && (get_gnome_hint (*win, WIN_WORKSPACE) ==
91 get_gnome_hint (root, WIN_WORKSPACE)))
92 {
93 name = get_icon_name (*win);
94 if (name)
95 {
96 if (strlen (name) >= 25)
97 strcpy (name + 21, "...");
98 strcpy (label, name);
99 if (get_wm_state (*win) == IconicState)
100 sprintf (label, "[%s]", name);
101
102 add_menu_item (GTK_MENU (win_menu), label,
103 G_CALLBACK (raise_window), (gpointer) * win);
104 XFree (name);
105 }
106 }
107 if (win)
108 XFree (win);
109 }
110 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), win_menu);
111 }
112
113 /***This must remain at the end of the file.*****
114 * vi:set sw=2 ts=2: *
115 * vi:set cindent cinoptions={1s,>2s,^-1s,n-1s: *
116 * vi:set foldmethod=marker: *
117 * vi:set foldmarker=���,���: *
118 ************************************************/
119
120