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 Ben 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 void desk_menu_update(ObMenuFrame *frame, gpointer data)
43 ObMenu *menu = frame->menu;
44 DesktopData *d = data;
47 gboolean icons = FALSE;
48 gboolean empty = TRUE;
50 menu_clear_entries(menu);
52 for (it = focus_order[d->desktop], i = 0; it; it = g_list_next(it), ++i) {
53 ObClient *c = it->data;
54 if (client_normal(c) && (!c->skip_taskbar || c->iconic)) {
58 const ObClientIcon *icon;
62 if (!icons && c->iconic) {
64 menu_add_separator(menu, -1);
67 act = action_from_string("Activate",
68 OB_USER_ACTION_MENU_SELECTION);
69 act->data.activate.any.c = c;
70 acts = g_slist_append(acts, act);
71 act = action_from_string("Desktop",
72 OB_USER_ACTION_MENU_SELECTION);
73 act->data.desktop.desk = d->desktop;
74 acts = g_slist_append(acts, act);
75 e = menu_add_normal(menu, i,
76 (c->iconic ? c->icon_title : c->title), acts);
78 if (config_menu_client_list_icons
79 && (icon = client_icon(c, 32, 32))) {
80 e->data.normal.icon_width = icon->width;
81 e->data.normal.icon_height = icon->height;
82 e->data.normal.icon_data = icon->data;
94 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
95 act->data.desktop.desk = d->desktop;
96 acts = g_slist_append(acts, act);
97 e = menu_add_normal(menu, 0, _("Go there..."), acts);
98 if (d->desktop == screen_desktop)
99 e->data.normal.enabled = FALSE;
103 /* executes it using the client in the actions, since we set that
104 when we make the actions! */
105 static void desk_menu_execute(ObMenuEntry *self, guint state, gpointer data)
109 if (self->data.normal.actions) {
110 a = self->data.normal.actions->data;
111 action_run(self->data.normal.actions, a->data.any.c, state);
115 static void desk_menu_destroy(ObMenu *menu, gpointer data)
117 DesktopData *d = data;
121 desktop_menus = g_slist_remove(desktop_menus, menu);
124 static void self_update(ObMenuFrame *frame, gpointer data)
126 ObMenu *menu = frame->menu;
131 for (i = 0; i < screen_num_desktops; ++i) {
134 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
135 DesktopData *data = g_new(DesktopData, 1);
138 submenu = menu_new(name, screen_desktop_names[i], data);
139 menu_set_update_func(submenu, desk_menu_update);
140 menu_set_execute_func(submenu, desk_menu_execute);
141 menu_set_destroy_func(submenu, desk_menu_destroy);
143 menu_add_submenu(menu, i, name);
147 desktop_menus = g_slist_append(desktop_menus, submenu);
149 it = g_slist_next(it);
151 for (; it; it = next, ++i) {
152 next = g_slist_next(it);
154 desktop_menus = g_slist_delete_link(desktop_menus, it);
155 menu_entry_remove(menu_find_entry_id(menu, i));
159 static void client_dest(ObClient *client, gpointer data)
161 /* This concise function removes all references to a closed
162 * client in the client_list_menu, so we don't have to check
165 for (it = desktop_menus; it; it = g_slist_next(it)) {
166 ObMenu *mit = it->data;
168 for (eit = mit->entries; eit; eit = g_list_next(eit)) {
169 ObMenuEntry *meit = eit->data;
170 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL) {
171 ObAction *a = meit->data.normal.actions->data;
172 ObClient *c = a->data.any.c;
174 a->data.any.c = NULL;
180 void client_list_menu_startup(gboolean reconfig)
185 client_add_destructor(client_dest, NULL);
187 menu = menu_new(MENU_NAME, _("Desktops"), NULL);
188 menu_set_update_func(menu, self_update);
191 void client_list_menu_shutdown(gboolean reconfig)
194 client_remove_destructor(client_dest);