]> Dogcows Code - chaz/openbox/blob - openbox/client_list_menu.c
1) get rid of menu titles
[chaz/openbox] / openbox / client_list_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 client_list_menu.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
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 of the License, or
10 (at your option) 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 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "openbox.h"
21 #include "menu.h"
22 #include "menuframe.h"
23 #include "action.h"
24 #include "screen.h"
25 #include "client.h"
26 #include "focus.h"
27 #include "config.h"
28 #include "gettext.h"
29
30 #include <glib.h>
31
32 #define MENU_NAME "client-list-menu"
33
34 static GSList *desktop_menus;
35
36 typedef struct
37 {
38 guint desktop;
39 } DesktopData;
40
41 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
42 {
43 ObMenu *menu = frame->menu;
44 DesktopData *d = data;
45 GList *it;
46 gint i;
47 gboolean empty = TRUE;
48
49 menu_clear_entries(menu);
50
51 for (it = focus_order, i = 0; it; it = g_list_next(it), ++i) {
52 ObClient *c = it->data;
53 if (client_normal(c) && (!c->skip_taskbar || c->iconic) &&
54 (c->desktop == d->desktop || c->desktop == DESKTOP_ALL))
55 {
56 GSList *acts = NULL;
57 ObAction* act;
58 ObMenuEntry *e;
59 const ObClientIcon *icon;
60
61 empty = FALSE;
62
63 act = action_from_string("Activate",
64 OB_USER_ACTION_MENU_SELECTION);
65 act->data.activate.any.c = c;
66 acts = g_slist_append(acts, act);
67 act = action_from_string("Desktop",
68 OB_USER_ACTION_MENU_SELECTION);
69 act->data.desktop.desk = d->desktop;
70 acts = g_slist_append(acts, act);
71
72 if (c->iconic) {
73 gchar *title = g_strdup_printf("(%s)", c->icon_title);
74 e = menu_add_normal(menu, i, title, acts);
75 g_free(title);
76 } else
77 e = menu_add_normal(menu, i, c->title, acts);
78
79 if (config_menu_client_list_icons
80 && (icon = client_icon(c, 32, 32))) {
81 e->data.normal.icon_width = icon->width;
82 e->data.normal.icon_height = icon->height;
83 e->data.normal.icon_data = icon->data;
84 }
85 }
86 }
87
88 if (empty) {
89 /* no entries */
90
91 GSList *acts = NULL;
92 ObAction* act;
93 ObMenuEntry *e;
94
95 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
96 act->data.desktop.desk = d->desktop;
97 acts = g_slist_append(acts, act);
98 e = menu_add_normal(menu, 0, _("Go there..."), acts);
99 if (d->desktop == screen_desktop)
100 e->data.normal.enabled = FALSE;
101 }
102 }
103
104 /* executes it using the client in the actions, since we set that
105 when we make the actions! */
106 static void desk_menu_execute(ObMenuEntry *self, guint state, gpointer data,
107 Time time)
108 {
109 ObAction *a;
110
111 if (self->data.normal.actions) {
112 a = self->data.normal.actions->data;
113 action_run(self->data.normal.actions, a->data.any.c, state, time);
114 }
115 }
116
117 static void desk_menu_destroy(ObMenu *menu, gpointer data)
118 {
119 DesktopData *d = data;
120
121 g_free(d);
122
123 desktop_menus = g_slist_remove(desktop_menus, menu);
124 }
125
126 static void self_update(ObMenuFrame *frame, gpointer data)
127 {
128 ObMenu *menu = frame->menu;
129 guint i;
130 GSList *it, *next;
131
132 it = desktop_menus;
133 for (i = 0; i < screen_num_desktops; ++i) {
134 if (!it) {
135 ObMenu *submenu;
136 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
137 DesktopData *data = g_new(DesktopData, 1);
138
139 data->desktop = i;
140 submenu = menu_new(name, screen_desktop_names[i], data);
141 menu_set_update_func(submenu, desk_menu_update);
142 menu_set_execute_func(submenu, desk_menu_execute);
143 menu_set_destroy_func(submenu, desk_menu_destroy);
144
145 menu_add_submenu(menu, i, name);
146
147 g_free(name);
148
149 desktop_menus = g_slist_append(desktop_menus, submenu);
150 } else
151 it = g_slist_next(it);
152 }
153 for (; it; it = next, ++i) {
154 next = g_slist_next(it);
155 menu_free(it->data);
156 desktop_menus = g_slist_delete_link(desktop_menus, it);
157 menu_entry_remove(menu_find_entry_id(menu, i));
158 }
159 }
160
161 static void client_dest(ObClient *client, gpointer data)
162 {
163 /* This concise function removes all references to a closed
164 * client in the client_list_menu, so we don't have to check
165 * in client.c */
166 GSList *it;
167 for (it = desktop_menus; it; it = g_slist_next(it)) {
168 ObMenu *mit = it->data;
169 GList *eit;
170 for (eit = mit->entries; eit; eit = g_list_next(eit)) {
171 ObMenuEntry *meit = eit->data;
172 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL) {
173 ObAction *a = meit->data.normal.actions->data;
174 ObClient *c = a->data.any.c;
175 if (c == client)
176 a->data.any.c = NULL;
177 }
178 }
179 }
180 }
181
182 void client_list_menu_startup(gboolean reconfig)
183 {
184 ObMenu *menu;
185
186 if (!reconfig)
187 client_add_destructor(client_dest, NULL);
188
189 menu = menu_new(MENU_NAME, _("Desktops"), NULL);
190 menu_set_update_func(menu, self_update);
191 }
192
193 void client_list_menu_shutdown(gboolean reconfig)
194 {
195 if (!reconfig)
196 client_remove_destructor(client_dest);
197 }
This page took 0.044036 seconds and 5 git commands to generate.