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) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "menuframe.h"
30 #define MENU_NAME "client-list-menu"
32 static GSList *desktop_menus;
38 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
40 ObMenu *menu = frame->menu;
41 DesktopData *d = data;
44 gboolean icons = FALSE;
45 gboolean empty = TRUE;
47 menu_clear_entries(menu);
49 for (it = focus_order[d->desktop], i = 0; it; it = g_list_next(it), ++i) {
50 ObClient *c = it->data;
51 if (client_normal(c)) {
59 if (!icons && c->iconic) {
61 menu_add_separator(menu, -1);
64 act = action_from_string("Activate",
65 OB_USER_ACTION_MENU_SELECTION);
66 act->data.activate.any.c = c;
67 acts = g_slist_prepend(NULL, act);
68 e = menu_add_normal(menu, i,
69 (c->iconic ? c->icon_title : c->title), acts);
71 if ((icon = client_icon(c, 32, 32))) {
72 e->data.normal.icon_width = icon->width;
73 e->data.normal.icon_height = icon->height;
74 e->data.normal.icon_data = icon->data;
84 act = action_from_string("Desktop", OB_USER_ACTION_MENU_SELECTION);
85 act->data.desktop.desk = d->desktop;
86 acts = g_slist_prepend(NULL, act);
87 menu_add_normal(menu, 0, "Switch to...", acts);
91 /* executes it using the client in the actions, since we set that
92 when we make the actions! */
93 static void desk_menu_execute(ObMenuEntry *self, guint state, gpointer data)
97 for (it = self->data.normal.actions; it; it = g_slist_next(it))
99 ObAction *act = it->data;
100 action_run(it->data, act->data.any.c, state);
104 static void desk_menu_destroy(ObMenu *menu, gpointer data)
106 DesktopData *d = data;
110 desktop_menus = g_slist_remove(desktop_menus, menu);
113 static void self_update(ObMenuFrame *frame, gpointer data)
115 ObMenu *menu = frame->menu;
120 for (i = 0; i < screen_num_desktops; ++i) {
123 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
124 DesktopData *data = g_new(DesktopData, 1);
127 submenu = menu_new(name, screen_desktop_names[i], data);
128 menu_set_update_func(submenu, desk_menu_update);
129 menu_set_execute_func(submenu, desk_menu_execute);
130 menu_set_destroy_func(submenu, desk_menu_destroy);
132 menu_add_submenu(menu, i, name);
136 desktop_menus = g_slist_append(desktop_menus, submenu);
138 it = g_slist_next(it);
140 for (; it; it = next, ++i) {
141 next = g_slist_next(it);
143 desktop_menus = g_slist_delete_link(desktop_menus, it);
144 menu_entry_remove(menu_find_entry_id(menu, i));
148 void client_list_menu_startup()
152 menu = menu_new(MENU_NAME, _("Desktops"), NULL);
153 menu_set_update_func(menu, self_update);