From d1c614d785f7604f67dc6e9d285c8cdf5d13b2ef Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 24 Jan 2011 17:06:41 -0500 Subject: [PATCH] WIP: Add an xdg applications menu (it doesn't have anything in it yet, but it does make a linkbase) --- Makefile.am | 2 + openbox/apps_menu.c | 120 ++++++++++++++++++++++++++++++++++++++++++++ openbox/apps_menu.h | 25 +++++++++ openbox/menu.c | 3 ++ 4 files changed, 150 insertions(+) create mode 100644 openbox/apps_menu.c create mode 100644 openbox/apps_menu.h diff --git a/Makefile.am b/Makefile.am index e63184e0..33bcdf7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -236,6 +236,8 @@ openbox_openbox_SOURCES = \ openbox/actions/unfocus.c \ openbox/actions.c \ openbox/actions.h \ + openbox/apps_menu.c \ + openbox/apps_menu.h \ openbox/client.c \ openbox/client.h \ openbox/client_list_menu.c \ diff --git a/openbox/apps_menu.c b/openbox/apps_menu.c new file mode 100644 index 00000000..d46ba6ed --- /dev/null +++ b/openbox/apps_menu.c @@ -0,0 +1,120 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + apps_menu.c for the Openbox window manager + Copyright (c) 2011 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#include "openbox.h" +#include "menu.h" +#include "menuframe.h" +#include "screen.h" +#include "apps_menu.h" +#include "config.h" +#include "gettext.h" +#include "obt/linkbase.h" +#include "obt/link.h" +#include "obt/paths.h" + +#include + +#define MENU_NAME "apps-menu" + +static ObMenu *apps_menu; +static ObtLinkBase *linkbase; +static gboolean dirty; + +static void self_destroy(ObMenu *menu, gpointer data) +{ + obt_linkbase_unref(linkbase); + linkbase = NULL; +} + +static void self_cleanup(ObMenu *menu, gpointer data) +{ + menu_clear_entries(menu); +} + +static gboolean self_update(ObMenuFrame *frame, gpointer data) +{ + ObMenu *menu = frame->menu; + ObMenuEntry *e; + + if (!dirty) return TRUE; /* nothing has changed to be updated */ + +/* + menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]); + + gchar *title = g_strdup_printf("(%s)", c->icon_title); + e = menu_add_normal(menu, desktop, title, NULL, FALSE); + g_free(title); + + if (config_menu_show_icons) { + e->data.normal.icon = client_icon(c); + RrImageRef(e->data.normal.icon); + e->data.normal.icon_alpha = + c->iconic ? OB_ICONIC_ALPHA : 0xff; + } + + e->data.normal.data = link; +*/ + + return TRUE; /* always show the menu */ +} + +static void menu_execute(ObMenuEntry *self, ObMenuFrame *f, + ObClient *c, guint state, gpointer data) +{ +#if 0 + ObClient *t = self->data.normal.data; + if (t) { /* it's set to NULL if its destroyed */ + gboolean here = state & ShiftMask; + + client_activate(t, TRUE, here, TRUE, TRUE, TRUE); + /* if the window is omnipresent then we need to go to its + desktop */ + if (!here && t->desktop == DESKTOP_ALL) + screen_set_desktop(self->id, FALSE); + } +#endif +} + +void linkbase_update(ObtLinkBase *lb, gpointer data) +{ + dirty = TRUE; +} + +void apps_menu_startup(gboolean reconfig) +{ + if (!reconfig) { + ObtPaths *paths; + + paths = obt_paths_new(); + /* XXX allow more environments, like GNOME or KDE, to be included */ + linkbase = obt_linkbase_new(paths, ob_locale_msg, + OBT_LINK_ENV_OPENBOX); + obt_paths_unref(paths); + } + + apps_menu = menu_new(MENU_NAME, _("Applications"), TRUE, NULL); + menu_set_update_func(apps_menu, self_update); + menu_set_cleanup_func(apps_menu, self_cleanup); + menu_set_execute_func(apps_menu, menu_execute); + menu_set_destroy_func(apps_menu, self_destroy); +} + +void apps_menu_shutdown(gboolean reconfig) +{ + /* freed by the hash table */ +} diff --git a/openbox/apps_menu.h b/openbox/apps_menu.h new file mode 100644 index 00000000..ca219c30 --- /dev/null +++ b/openbox/apps_menu.h @@ -0,0 +1,25 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + + apps_menu.h for the Openbox window manager + Copyright (c) 2011 Dana Jansens + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + See the COPYING file for a copy of the GNU General Public License. +*/ + +#ifndef ob__apps_menu_h +#define ob__apps_menu_h + +void apps_menu_startup(gboolean reconfig); +void apps_menu_shutdown(gboolean reconfig); + +#endif diff --git a/openbox/menu.c b/openbox/menu.c index c97fb56b..2befac3a 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -31,6 +31,7 @@ #include "geom.h" #include "misc.h" #include "client_menu.h" +#include "apps_menu.h" #include "client_list_menu.h" #include "client_list_combined_menu.h" #include "gettext.h" @@ -67,6 +68,7 @@ void menu_startup(gboolean reconfig) menu_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)menu_destroy_hash_value); + apps_menu_startup(reconfig); client_list_menu_startup(reconfig); client_list_combined_menu_startup(reconfig); client_menu_startup(); @@ -119,6 +121,7 @@ void menu_shutdown(gboolean reconfig) client_list_combined_menu_shutdown(reconfig); client_list_menu_shutdown(reconfig); + apps_menu_shutdown(reconfig); g_hash_table_destroy(menu_hash); menu_hash = NULL; -- 2.34.1