1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client_list_menu.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
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.
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.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "menuframe.h"
32 #define MENU_NAME "client-list-menu"
34 static GSList *desktop_menus;
41 static gboolean desk_menu_update(ObMenuFrame *frame, gpointer data)
43 ObMenu *menu = frame->menu;
44 DesktopData *d = data;
47 gboolean empty = TRUE;
48 gboolean onlyiconic = TRUE;
50 menu_clear_entries(menu);
52 for (it = focus_order, i = 0; it; it = g_list_next(it), ++i) {
53 ObClient *c = it->data;
54 if (client_normal(c) && (!c->skip_taskbar || c->iconic) &&
55 (c->desktop == d->desktop || c->desktop == DESKTOP_ALL))
60 const ObClientIcon *icon;
64 act = action_from_string("Activate",
65 OB_USER_ACTION_MENU_SELECTION);
66 act->data.activate.any.c = c;
67 acts = g_slist_append(acts, act);
68 act = action_from_string("Desktop",
69 OB_USER_ACTION_MENU_SELECTION);
70 act->data.desktop.desk = d->desktop;
71 acts = g_slist_append(acts, act);
74 gchar *title = g_strdup_printf("(%s)", c->icon_title);
75 e = menu_add_normal(menu, i, title, acts, FALSE);
79 e = menu_add_normal(menu, i, c->title, acts, FALSE);
82 if (config_menu_client_list_icons
83 && (icon = client_icon(c, 32, 32))) {
84 e->data.normal.icon_width = icon->width;
85 e->data.normal.icon_height = icon->height;
86 e->data.normal.icon_data = icon->data;
87 e->data.normal.icon_alpha = c->iconic ? OB_ICONIC_ALPHA : 0xff;
92 if (empty || onlyiconic) {
93 /* no entries or only iconified windows, so add a
94 * way to go to this desktop without uniconifying a window */
96 menu_add_separator(menu, -1, NULL);
102 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
103 act->data.desktop.desk = d->desktop;
104 acts = g_slist_append(acts, act);
105 e = menu_add_normal(menu, 0, _("Go there..."), acts, TRUE);
106 if (d->desktop == screen_desktop)
107 e->data.normal.enabled = FALSE;
109 return TRUE; /* always show */
112 /* executes it using the client in the actions, since we set that
113 when we make the actions! */
114 static void desk_menu_execute(ObMenuEntry *self, ObMenuFrame *f,
115 ObClient *c, guint state, gpointer data,
120 if (self->data.normal.actions) {
121 a = self->data.normal.actions->data;
122 action_run(self->data.normal.actions, a->data.any.c, state, time);
126 static void desk_menu_destroy(ObMenu *menu, gpointer data)
128 DesktopData *d = data;
132 desktop_menus = g_slist_remove(desktop_menus, menu);
135 static gboolean self_update(ObMenuFrame *frame, gpointer data)
137 ObMenu *menu = frame->menu;
140 menu_clear_entries(menu);
142 while (desktop_menus) {
143 menu_free(desktop_menus->data);
144 desktop_menus = g_slist_delete_link(desktop_menus, desktop_menus);
147 for (i = 0; i < screen_num_desktops; ++i) {
149 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
150 DesktopData *data = g_new(DesktopData, 1);
153 submenu = menu_new(name, screen_desktop_names[i], FALSE, data);
154 menu_set_update_func(submenu, desk_menu_update);
155 menu_set_execute_func(submenu, desk_menu_execute);
156 menu_set_destroy_func(submenu, desk_menu_destroy);
158 menu_add_submenu(menu, i, name);
162 desktop_menus = g_slist_append(desktop_menus, submenu);
165 return TRUE; /* always show */
168 static void client_dest(ObClient *client, gpointer data)
170 /* This concise function removes all references to a closed
171 * client in the client_list_menu, so we don't have to check
174 for (it = desktop_menus; it; it = g_slist_next(it)) {
175 ObMenu *mit = it->data;
177 for (eit = mit->entries; eit; eit = g_list_next(eit)) {
178 ObMenuEntry *meit = eit->data;
179 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL) {
180 ObAction *a = meit->data.normal.actions->data;
181 ObClient *c = a->data.any.c;
183 a->data.any.c = NULL;
189 void client_list_menu_startup(gboolean reconfig)
194 client_add_destroy_notify(client_dest, NULL);
196 menu = menu_new(MENU_NAME, _("Desktops"), TRUE, NULL);
197 menu_set_update_func(menu, self_update);
200 void client_list_menu_shutdown(gboolean reconfig)
203 client_remove_destroy_notify(client_dest);