add the client_list_menu plugin

This commit is contained in:
Dana Jansens 2003-08-14 06:01:39 +00:00
parent a88e58e227
commit cbd0e4d308
4 changed files with 160 additions and 1 deletions

View file

@ -30,7 +30,8 @@ plugin_LTLIBRARIES = \
plugins/menu/timed_menu.la \ plugins/menu/timed_menu.la \
plugins/menu/fifo_menu.la \ plugins/menu/fifo_menu.la \
plugins/menu/client_menu.la \ plugins/menu/client_menu.la \
plugins/menu/include_menu.la plugins/menu/include_menu.la \
plugins/menu/client_list_menu.la
if OBCONF if OBCONF
bin_PROGRAMS += \ bin_PROGRAMS += \
@ -265,6 +266,19 @@ plugins_menu_include_menu_la_LDFLAGS = \
plugins_menu_include_menu_la_SOURCES = \ plugins_menu_include_menu_la_SOURCES = \
plugins/menu/include_menu.c plugins/menu/include_menu.c
plugins_menu_client_list_menu_la_CPPFLAGS = \
$(XFT_CFLAGS) \
$(GLIB_CFLAGS) \
$(LIBSN_CFLAGS) \
$(XML_CFLAGS) \
-DPLUGINDIR=\"$(plugindir)\" \
-DG_LOG_DOMAIN=\"Plugin-Client-List-Menu\"
plugins_menu_client_list_menu_la_LDFLAGS = \
-module \
-avoid-version
plugins_menu_client_list_menu_la_SOURCES = \
plugins/menu/client_list_menu.c
## obconf ## ## obconf ##

View file

@ -161,6 +161,7 @@ void plugin_loadall(ObParseInst *i)
/* XXX rm me when the parser loads me magically */ /* XXX rm me when the parser loads me magically */
plugin_open("client_menu", i); plugin_open("client_menu", i);
plugin_open("client_list_menu", i);
} else { } else {
/* load the plugins in the rc file */ /* load the plugins in the rc file */
while (g_io_channel_read_line(io, &name, NULL, NULL, &err) == while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==

View file

@ -3,9 +3,11 @@
timed_menu.la timed_menu.la
fifo_menu.la fifo_menu.la
client_menu.la client_menu.la
client_list_menu.la
include_menu.la include_menu.la
.dirstamp .dirstamp
plugins_menu_client_menu_la-client_menu.lo plugins_menu_client_menu_la-client_menu.lo
plugins_menu_client_list_menu_la-client_list_menu.lo
plugins_menu_fifo_menu_la-fifo_menu.lo plugins_menu_fifo_menu_la-fifo_menu.lo
plugins_menu_timed_menu_la-timed_menu.lo plugins_menu_timed_menu_la-timed_menu.lo
plugins_menu_include_menu_la-include_menu.lo plugins_menu_include_menu_la-include_menu.lo

View file

@ -0,0 +1,142 @@
#include "kernel/openbox.h"
#include "kernel/menu.h"
#include "kernel/action.h"
#include "kernel/screen.h"
#include "kernel/client.h"
#include "kernel/focus.h"
#include "render/theme.h"
#include <glib.h>
static char *PLUGIN_NAME = "client_list_menu";
typedef struct {
GSList *submenus;
} Client_List_Menu_Data;
typedef struct {
guint desktop;
} Client_List_Desktop_Menu_Data;
#define CLIENT_LIST_MENU(m) ((ObMenu *)m)
#define CLIENT_LIST_MENU_DATA(m) ((Client_List_Menu_Data *)((ObMenu *)m)->plugin_data)
#define CLIENT_LIST_DESKTOP_MENU(m) ((ObMenu *)m)
#define CLIENT_LIST_DESKTOP_MENU_DATA(m) ((Client_List_Desktop_Menu_Data *)((ObMenu *)m)->plugin_data)
static void self_update(ObMenu *self);
static void self_destroy(ObMenu *self);
void plugin_setup_config() { }
void plugin_shutdown() { }
void plugin_destroy (ObMenu *m) { }
void *plugin_create()
{
ObMenu *menu = menu_new_full("Desktops", "client-list-menu", NULL,
NULL, self_update, NULL,
NULL, NULL, self_destroy);
menu->plugin = PLUGIN_NAME;
menu->plugin_data = g_new(Client_List_Menu_Data, 1);
CLIENT_LIST_MENU_DATA(menu)->submenus = NULL;
return (void *)menu;
}
void plugin_startup()
{
plugin_create("client_list_menu");
}
static void desk_update(ObMenu *self)
{
GList *it;
guint desk;
menu_clear(self);
desk = CLIENT_LIST_DESKTOP_MENU_DATA(self)->desktop;
for (it = focus_order[desk]; it; it = g_list_next(it)) {
ObClient *c = (ObClient *)it->data;
if (client_normal(c)) {
ObAction* a = action_from_string("activate");
a->data.activate.c = c;
menu_add_entry(self, menu_entry_new((c->iconic ?
c->icon_title :
c->title), a));
}
}
menu_render(self);
}
static void desk_selected(ObMenuEntry *entry,
unsigned int button, unsigned int x, unsigned int y)
{
entry->action->data.activate.here = (button == 2);
entry->parent->client = entry->action->data.activate.c;
menu_entry_fire(entry, button, x, y);
}
static void desk_destroy(ObMenu *self)
{
g_free(self->plugin_data);
}
static void self_update(ObMenu *self)
{
guint i, n;
ObMenu *deskmenu;
gchar *s;
GList *eit, *enext;
GSList *sit, *snext;
n = g_slist_length(CLIENT_LIST_MENU_DATA(self)->submenus);
for (i = 0; i < screen_num_desktops; ++i) {
if (i >= n) {
s = g_strdup_printf("client-list-menu-desktop-%d", i);
deskmenu = menu_new_full(screen_desktop_names[i], s, self,
NULL,
desk_update, desk_selected, NULL, NULL,
desk_destroy);
g_free(s);
deskmenu->plugin = PLUGIN_NAME;
deskmenu->plugin_data = g_new(Client_List_Desktop_Menu_Data, 1);
CLIENT_LIST_DESKTOP_MENU_DATA(deskmenu)->desktop = i;
CLIENT_LIST_MENU_DATA(self)->submenus =
g_slist_append(CLIENT_LIST_MENU_DATA(self)->submenus,
deskmenu);
}
menu_add_entry(self, menu_entry_new_submenu(screen_desktop_names[i],
deskmenu));
}
for (eit = g_list_nth(self->entries, i); eit; eit = enext) {
enext = g_list_next(eit);
menu_entry_free(eit->data);
self->entries = g_list_delete_link(self->entries, eit);
}
for (sit = g_slist_nth(CLIENT_LIST_MENU_DATA(self)->submenus, i);
sit; sit = snext) {
snext = g_slist_next(sit);
menu_free(sit->data);
CLIENT_LIST_MENU_DATA(self)->submenus =
g_slist_delete_link(CLIENT_LIST_MENU_DATA(self)->submenus, sit);
}
menu_render(self);
}
static void self_destroy(ObMenu *self)
{
g_free(self->plugin_data);
}