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-combined-menu"
34 ObMenu *combined_menu;
36 static void self_update(ObMenuFrame *frame, gpointer data)
38 ObMenu *menu = frame->menu;
42 gboolean icons = FALSE;
45 menu_clear_entries(menu);
47 for (desktop = 0; desktop < screen_num_desktops; desktop++) {
48 gboolean empty = TRUE;
50 /* Don't need a separator at the very top */
52 menu_add_separator(menu, -1);
53 e = menu_add_normal(menu, -1, NULL, NULL);
54 e->data.normal.enabled = FALSE;
55 e->data.normal.label = g_strdup(screen_desktop_names[desktop]);
56 /* The one at the bottom will always have entries below it though */
57 menu_add_separator(menu, -1);
58 for (it = focus_order[desktop], i = 0; it; it = g_list_next(it), ++i) {
59 ObClient *c = it->data;
60 if (client_normal(c) && (!c->skip_taskbar || c->iconic)) {
63 const ObClientIcon *icon;
67 if (!icons && c->iconic) {
69 menu_add_separator(menu, -1);
72 act = action_from_string("Activate",
73 OB_USER_ACTION_MENU_SELECTION);
74 act->data.activate.any.c = c;
75 acts = g_slist_append(acts, act);
76 act = action_from_string("Desktop",
77 OB_USER_ACTION_MENU_SELECTION);
78 act->data.desktop.desk = desktop;
79 acts = g_slist_append(acts, act);
80 e = menu_add_normal(menu, i, (c->iconic ?
81 c->icon_title : c->title), acts);
83 if (config_menu_client_list_icons
84 && (icon = client_icon(c, 32, 32))) {
85 e->data.normal.icon_width = icon->width;
86 e->data.normal.icon_height = icon->height;
87 e->data.normal.icon_data = icon->data;
100 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
101 act->data.desktop.desk = desktop;
102 acts = g_slist_append(acts, act);
103 e = menu_add_normal(menu, 0, _("Go there..."), acts);
104 if (desktop == screen_desktop)
105 e->data.normal.enabled = FALSE;
110 /* executes it using the client in the actions, since we set that
111 when we make the actions! */
112 static void menu_execute(ObMenuEntry *self, guint state, gpointer data,
117 if (self->data.normal.actions) {
118 a = self->data.normal.actions->data;
119 action_run(self->data.normal.actions, a->data.any.c, state, time);
123 static void client_dest(ObClient *client, gpointer data)
125 /* This concise function removes all references to a closed
126 * client in the client_list_menu, so we don't have to check
129 for (eit = combined_menu->entries; eit; eit = g_list_next(eit)) {
130 ObMenuEntry *meit = eit->data;
131 if (meit->type == OB_MENU_ENTRY_TYPE_NORMAL &&
132 meit->data.normal.actions)
134 ObAction *a = meit->data.normal.actions->data;
135 ObClient *c = a->data.any.c;
137 a->data.any.c = NULL;
142 void client_list_combined_menu_startup(gboolean reconfig)
145 client_add_destructor(client_dest, NULL);
147 combined_menu = menu_new(MENU_NAME, _("Windows"), NULL);
148 menu_set_update_func(combined_menu, self_update);
149 menu_set_execute_func(combined_menu, menu_execute);
152 void client_list_combined_menu_shutdown(gboolean reconfig)
155 client_remove_destructor(client_dest);