]> Dogcows Code - chaz/openbox/blob - openbox/client_list_menu.c
add the activate action. it will replace the focus action, as it can just focus witho...
[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-2007 Dana 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 "screen.h"
24 #include "client.h"
25 #include "focus.h"
26 #include "config.h"
27 #include "gettext.h"
28
29 #include <glib.h>
30
31 #define MENU_NAME "client-list-menu"
32
33 static GSList *desktop_menus;
34
35 typedef struct
36 {
37 guint desktop;
38 } DesktopData;
39
40 static gboolean desk_menu_update(ObMenuFrame *frame, gpointer data)
41 {
42 ObMenu *menu = frame->menu;
43 DesktopData *d = data;
44 GList *it;
45 gboolean empty = TRUE;
46 gboolean onlyiconic = TRUE;
47
48 menu_clear_entries(menu);
49
50 for (it = focus_order; it; it = g_list_next(it)) {
51 ObClient *c = it->data;
52 if (client_normal(c) && (!c->skip_taskbar || c->iconic) &&
53 (c->desktop == d->desktop || c->desktop == DESKTOP_ALL))
54 {
55 ObMenuEntry *e;
56 const ObClientIcon *icon;
57
58 empty = FALSE;
59
60 if (c->iconic) {
61 gchar *title = g_strdup_printf("(%s)", c->icon_title);
62 e = menu_add_normal(menu, -1, title, NULL, FALSE);
63 g_free(title);
64 } else {
65 onlyiconic = FALSE;
66 e = menu_add_normal(menu, -1, c->title, NULL, FALSE);
67 }
68
69 if (config_menu_client_list_icons
70 && (icon = client_icon(c, 32, 32))) {
71 e->data.normal.icon_width = icon->width;
72 e->data.normal.icon_height = icon->height;
73 e->data.normal.icon_data = icon->data;
74 e->data.normal.icon_alpha = c->iconic ? OB_ICONIC_ALPHA : 0xff;
75 }
76
77 e->data.normal.data = c;
78 }
79 }
80
81 if (empty || onlyiconic) {
82 ObMenuEntry *e;
83
84 /* no entries or only iconified windows, so add a
85 * way to go to this desktop without uniconifying a window */
86 if (!empty)
87 menu_add_separator(menu, -1, NULL);
88
89 e = menu_add_normal(menu, d->desktop, _("Go there..."), NULL, TRUE);
90 if (d->desktop == screen_desktop)
91 e->data.normal.enabled = FALSE;
92 }
93 return TRUE; /* always show */
94 }
95
96 static void desk_menu_execute(ObMenuEntry *self, ObMenuFrame *f,
97 ObClient *c, guint state, gpointer data)
98 {
99 if (self->id == -1) {
100 if (self->data.normal.data) /* it's set to NULL if its destroyed */
101 client_activate(self->data.normal.data, FALSE, TRUE, TRUE, TRUE);
102 }
103 else
104 screen_set_desktop(self->id, TRUE);
105 }
106
107 static void desk_menu_destroy(ObMenu *menu, gpointer data)
108 {
109 DesktopData *d = data;
110
111 g_free(d);
112
113 desktop_menus = g_slist_remove(desktop_menus, menu);
114 }
115
116 static gboolean self_update(ObMenuFrame *frame, gpointer data)
117 {
118 ObMenu *menu = frame->menu;
119 guint i;
120
121 menu_clear_entries(menu);
122
123 while (desktop_menus) {
124 menu_free(desktop_menus->data);
125 desktop_menus = g_slist_delete_link(desktop_menus, desktop_menus);
126 }
127
128 for (i = 0; i < screen_num_desktops; ++i) {
129 ObMenu *submenu;
130 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
131 DesktopData *data = g_new(DesktopData, 1);
132
133 data->desktop = i;
134 submenu = menu_new(name, screen_desktop_names[i], FALSE, data);
135 menu_set_update_func(submenu, desk_menu_update);
136 menu_set_execute_func(submenu, desk_menu_execute);
137 menu_set_destroy_func(submenu, desk_menu_destroy);
138
139 menu_add_submenu(menu, i, name);
140
141 g_free(name);
142
143 desktop_menus = g_slist_append(desktop_menus, submenu);
144 }
145
146 return TRUE; /* always show */
147 }
148
149 static void client_dest(ObClient *client, gpointer data)
150 {
151 /* This concise function removes all references to a closed
152 * client in the client_list_menu, so we don't have to check
153 * in client.c */
154 GSList *it;
155 for (it = desktop_menus; it; it = g_slist_next(it)) {
156 ObMenu *mit = it->data;
157 GList *eit;
158 for (eit = mit->entries; eit; eit = g_list_next(eit)) {
159 ObMenuEntry *meit = eit->data;
160 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL &&
161 meit->data.normal.data == client)
162 {
163 meit->data.normal.data = NULL;
164 }
165 }
166 }
167 }
168
169 void client_list_menu_startup(gboolean reconfig)
170 {
171 ObMenu *menu;
172
173 if (!reconfig)
174 client_add_destroy_notify(client_dest, NULL);
175
176 menu = menu_new(MENU_NAME, _("Desktops"), TRUE, NULL);
177 menu_set_update_func(menu, self_update);
178 }
179
180 void client_list_menu_shutdown(gboolean reconfig)
181 {
182 if (!reconfig)
183 client_remove_destroy_notify(client_dest);
184 }
This page took 0.042185 seconds and 5 git commands to generate.