Some fixes and new bugs. Someone else can do the menus because it is

clear no one gives a fuck what I think and no one else wants a window
manager that doesn't suck the same balls as every other window manager.
This commit is contained in:
Scott Moynes 2003-08-11 21:19:17 +00:00
parent d94fba7262
commit a4f023cf3a
7 changed files with 160 additions and 26 deletions

View file

@ -142,8 +142,9 @@ void menu_entry_free(ObMenuEntry *self)
RrAppearanceFree(self->a_item);
RrAppearanceFree(self->a_disabled);
RrAppearanceFree(self->a_hilite);
RrAppearanceFree(self->a_submenu);
XDestroyWindow(ob_display, self->item);
XDestroyWindow(ob_display, self->submenu_pic);
g_free(self);
}
@ -273,13 +274,17 @@ void menu_add_entry(ObMenu *menu, ObMenuEntry *entry)
attrib.event_mask = ENTRY_EVENTMASK;
entry->item = createWindow(menu->items, CWEventMask, &attrib);
entry->submenu_pic = createWindow(menu->items, CWEventMask, &attrib);
XMapWindow(ob_display, entry->item);
XMapWindow(ob_display, entry->submenu_pic);
entry->a_item = entry->a_disabled = entry->a_hilite = NULL;
entry->a_item = entry->a_disabled = entry->a_hilite = entry->a_submenu
= NULL;
menu->invalid = TRUE;
g_hash_table_insert(window_map, &entry->item, menu);
g_hash_table_insert(window_map, &entry->submenu_pic, menu);
}
void menu_show(char *name, int x, int y, ObClient *client)
@ -473,9 +478,21 @@ void menu_control_mouseover(ObMenuEntry *self, gboolean enter)
a = screen_physical_area_monitor(self->parent->xin_area);
if (self->submenu->size.width + x >= a->x + a->width)
x = self->parent->location.x - self->submenu->size.width -
ob_rr_theme->bwidth + ob_rr_theme->menu_overlap;
if (self->submenu->size.width + x >= a->x + a->width) {
int newparentx = a->x + a->width
- self->submenu->size.width
- self->parent->size.width
- ob_rr_theme->bwidth
- ob_rr_theme->menu_overlap;
x = a->x + a->width - self->submenu->size.width
- ob_rr_theme->menu_overlap;
XWarpPointer(ob_display, None, None, 0, 0, 0, 0,
newparentx - self->parent->location.x, 0);
menu_show_full(self->parent, newparentx,
self->parent->location.y, self->parent->client);
}
menu_show_full(self->submenu, x,
self->parent->location.y + self->y,

View file

@ -114,9 +114,12 @@ struct _ObMenuEntry
/* render stuff */
Window item;
Window submenu_pic;
RrAppearance *a_item;
RrAppearance *a_disabled;
RrAppearance *a_hilite;
RrAppearance *a_submenu;
gint y;
gint min_w;
} MenuEntry;

View file

@ -45,8 +45,9 @@ void menu_render(ObMenu *self) {
e->a_item = RrAppearanceCopy(ob_rr_theme->a_menu_item);
e->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
e->a_hilite = RrAppearanceCopy(ob_rr_theme->a_menu_hilite);
e->a_submenu = RrAppearanceCopy(ob_rr_theme->a_menu_bullet);
}
e->a_item->texture[0].data.text.string = e->label;
RrMinsize(e->a_item, &e->min_w, &self->item_h);
self->size.width = MAX(self->size.width, e->min_w);
@ -97,11 +98,14 @@ void menu_render(ObMenu *self) {
void menu_entry_render(ObMenuEntry *self)
{
ObMenu *menu = self->parent;
RrAppearance *a;
RrAppearance *a, *s = NULL;
switch (self->render_type) {
case OB_MENU_ENTRY_RENDER_TYPE_SUBMENU:
/* TODO: submenu mask */
a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item)
: self->a_disabled;
s = self->a_submenu;
break;
case OB_MENU_ENTRY_RENDER_TYPE_BOOLEAN:
/* TODO: boolean check */
a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item)
@ -119,14 +123,23 @@ void menu_entry_render(ObMenuEntry *self)
g_assert_not_reached(); /* unhandled rendering type */
break;
}
ob_debug("%s %d\n", self->label, self->hilite);
XMoveResizeWindow(ob_display, self->item, 0, self->y,
menu->size.width, menu->item_h);
XMoveResizeWindow(ob_display, self->submenu_pic, menu->size.width - ob_rr_theme->bevel - 1, self->y,
8, 8);
a->surface.parent = menu->a_items;
a->surface.parentx = 0;
a->surface.parenty = self->y;
if (s) {
s->surface.parent = a;
s->surface.parentx = menu->size.width - 8;
s->surface.parenty = 0;
}
RrPaint(a, self->item, menu->size.width, menu->item_h);
if (s)
RrPaint(s, self->submenu_pic, 8, 8);
}

View file

@ -1,3 +1,25 @@
/*
* $Header$
*
* FFIO menu plugin
* Provides a menu from a FIFO located in ~/.openbox/fifo_menu/id
* Example:
* rc3:
* <menu id="fonk" label="fonk" plugin="fifo_menu"></menu>
* Menu format
* <fifo_menu>
* <item label="GLOVE.png">
* <action name="execute">
* <execute>
* bsetbg "/home/woodblock/.openbox/backgrounds/GLOVE.png"
* </execute>
* </action>
* </item>
* </fifo_menu>
*
* If the attribute pid="true" is in the <menu>
*/
#include <glib.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -94,8 +116,7 @@ void fifo_menu_handler(int fd, void *d) {
if (node &&
!xmlStrcasecmp(node->name, (const xmlChar*) "fifo_menu")) {
if ((node = parse_find_node("item", node->xmlChildrenNode)))
parse_menu_full(doc, node, menu, FALSE);
parse_menu_full(doc, node, menu, FALSE);
}
fifo_menu_clean_up(menu);

View file

@ -1,3 +1,35 @@
/*
* $Header$
*
* Timed menu plugin
* Provides a menu from either a periodically executing process or by
* periodically checking the timestamp of a file and loading if it has changed.
*
* Examples:
* Piped timed menu:
* rc3:
* <menu id="name" label="Piped menu" plugin="timed_menu" timeout="120"
* command="obcommand.py -c bsetbg -d ~/.openbox/backgrounds/" />
* timeout is in seconds
*
* Output of command:
* <timed_menu>
* <item label="GLOVE.png">
* <action name="execute">
* <execute>
* bsetbg "/home/woodblock/.openbox/backgrounds/GLOVE.png"
* </execute>
* </action>
* </item>
* </fifo_menu>
*
* stat() menu:
* <menu id="name" label="Stat menu" plugin="timed_menu" type="stat"
* timeout="120" file="~/.openbox/stat_menu" />
* stat_menu contents: same as timed menu
*
*/
#include <glib.h>
#include <stdlib.h>
#include <unistd.h>
@ -27,7 +59,7 @@ typedef enum {
typedef struct {
Timed_Menu_Type type;
ObTimer *timer;
char *command; /* for the PIPE */
char *command; /* command to run or file to stat() */
char *buf; /* buffer to hold partially read menu */
unsigned long buflen; /* how many bytes are in the buffer */
int fd; /* file descriptor to read menu from */
@ -43,7 +75,6 @@ void plugin_shutdown() { }
void timed_menu_clean_up(ObMenu *m) {
if (TIMED_MENU_DATA(m)->buf != NULL) {
fprintf(stderr, "%s", TIMED_MENU_DATA(m)->buf);
g_free(TIMED_MENU_DATA(m)->buf);
TIMED_MENU_DATA(m)->buf = NULL;
}
@ -60,8 +91,6 @@ void timed_menu_clean_up(ObMenu *m) {
waitpid(TIMED_MENU_DATA(m)->pid, NULL, 0);
TIMED_MENU_DATA(m)->pid = -1;
}
TIMED_MENU_DATA(m)->mtime = 0;
}
void timed_menu_read_pipe(int fd, void *d)
@ -109,9 +138,9 @@ void timed_menu_read_pipe(int fd, void *d)
node = xmlDocGetRootElement(doc);
if (!xmlStrcasecmp(node->name, (const xmlChar*) "timed_menu")) {
if ((node = parse_find_node("item", node->xmlChildrenNode)))
parse_menu_full(doc, node, menu, FALSE);
if (node &&
!xmlStrcasecmp(node->name, (const xmlChar*) "timed_menu")) {
parse_menu_full(doc, node, menu, FALSE);
}
timed_menu_clean_up(menu);
@ -176,9 +205,25 @@ void timed_menu_timeout_handler(ObTimer *t, void *d)
}
if (stat_buf.st_mtime > TIMED_MENU_DATA(data)->mtime) {
xmlDocPtr doc;
xmlNodePtr node;
g_warning("file changed");
TIMED_MENU_DATA(data)->mtime = stat_buf.st_mtime;
/* TODO: parse */
data->invalid = TRUE;
menu_clear(data);
doc = xmlParseFile(TIMED_MENU_DATA(data)->command);
node = xmlDocGetRootElement(doc);
if (node &&
!xmlStrcasecmp(node->name, (const xmlChar*) "timed_menu")) {
parse_menu_full(doc, node, data, FALSE);
}
timed_menu_clean_up(data);
}
}
}
@ -190,6 +235,8 @@ void *plugin_create(PluginMenuCreateData *data)
char *id;
char *label;
char *timeout;
char *type;
Timed_Menu_Data *d;
ObMenu *m;
@ -209,9 +256,19 @@ void *plugin_create(PluginMenuCreateData *data)
(label != NULL ? label : ""),
m));
if (!parse_attr_string("command", data->node, &d->command)) {
d->command = g_strdup("");
}
d->type = TIMED_MENU_PIPE;
if (parse_attr_string("type", data->node, &type) &&
!g_strcasecmp(type, "stat")) {
d->type = TIMED_MENU_STAT;
if (!parse_attr_string("file", data->node, &d->command)) {
d->command = g_strdup("");
}
} else
if (!parse_attr_string("command", data->node, &d->command)) {
d->command = g_strdup("");
}
if (parse_attr_string("timeout", data->node, &timeout)) {
char *endptr;
@ -222,7 +279,6 @@ void *plugin_create(PluginMenuCreateData *data)
} else
d->timer = timer_start(600 * 1000000, &timed_menu_timeout_handler, m);
d->type = TIMED_MENU_PIPE;
d->buf = NULL;
d->buflen = 0;
d->fd = -1;

View file

@ -59,6 +59,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
theme->a_menu_item = RrAppearanceNew(inst, 1);
theme->a_menu_disabled = RrAppearanceNew(inst, 1);
theme->a_menu_hilite = RrAppearanceNew(inst, 1);
theme->a_menu_bullet = RrAppearanceNew(inst, 1);
theme->a_clear = RrAppearanceNew(inst, 0);
theme->app_hilite_bg = RrAppearanceNew(inst, 0);
@ -242,6 +243,9 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
if (!read_color(db, inst,
"menu.frame.textColor", &theme->menu_color))
theme->menu_color = RrColorNew(inst, 0xff, 0xff, 0xff);
if (!read_color(db, inst,
"menu.bullet.picColor", &theme->menu_color))
theme->menu_bullet_color = RrColorNew(inst, 0x00, 0x00, 0x00);
if (!read_color(db, inst,
"menu.frame.disableColor", &theme->menu_disabled_color))
theme->menu_disabled_color = RrColorNew(inst, 0, 0, 0);
@ -249,6 +253,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
"menu.hilite.textColor", &theme->menu_hilite_color))
theme->menu_hilite_color = RrColorNew(inst, 0, 0, 0);
if (read_mask(inst, "max.xbm", theme, &theme->max_mask)) {
if (!read_mask(inst, "max_pressed.xbm", theme,
&theme->max_pressed_mask)) {
@ -390,7 +395,14 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
theme->close_pressed_mask = RrPixmapMaskCopy(theme->close_mask);
theme->close_disabled_mask = RrPixmapMaskCopy(theme->close_mask);
theme->close_hover_mask = RrPixmapMaskCopy(theme->close_mask);
}
}
if (!read_mask(inst, "bullet.xbm", theme, &theme->menu_bullet_mask)) {
unsigned char data[] =
{ 0x18, 0x30, 0x60, 0xfe, 0xfe, 0x60, 0x30, 0x18 };
theme->menu_bullet_mask = RrPixmapMaskNew(inst, 8, 8,
(gchar *)data);
}
/* read the decoration textures */
if (!read_appearance(db, inst,
@ -616,6 +628,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
theme->a_menu_item->surface.grad =
theme->a_menu_disabled->surface.grad =
theme->a_menu_bullet->surface.grad =
theme->app_icon->surface.grad = RR_SURFACE_PARENTREL;
theme->a_menu_item->texture[0].type =
@ -632,6 +645,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
theme->menu_disabled_color;
theme->a_menu_hilite->texture[0].data.text.color =
theme->menu_hilite_color;
theme->a_menu_bullet->texture[0].data.mask.color =
theme->menu_bullet_color;
theme->a_disabled_focused_max->texture[0].type =
theme->a_disabled_unfocused_max->texture[0].type =
@ -678,7 +693,9 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
theme->a_focused_unpressed_iconify->texture[0].type =
theme->a_focused_pressed_iconify->texture[0].type =
theme->a_unfocused_unpressed_iconify->texture[0].type =
theme->a_unfocused_pressed_iconify->texture[0].type = RR_TEXTURE_MASK;
theme->a_unfocused_pressed_iconify->texture[0].type =
theme->a_menu_bullet->texture[0].type = RR_TEXTURE_MASK;
theme->a_disabled_focused_max->texture[0].data.mask.mask =
theme->a_disabled_unfocused_max->texture[0].data.mask.mask =
theme->max_disabled_mask;
@ -863,6 +880,7 @@ void RrThemeFree(RrTheme *theme)
RrPixmapMaskFree(theme->close_disabled_mask);
RrPixmapMaskFree(theme->close_hover_mask);
RrPixmapMaskFree(theme->close_pressed_mask);
RrPixmapMaskFree(theme->menu_bullet_mask);
RrFontClose(theme->winfont);
RrFontClose(theme->mtitlefont);

View file

@ -40,6 +40,7 @@ struct _RrTheme {
RrColor *titlebut_unfocused_unpressed_color;
RrColor *menu_title_color;
RrColor *menu_color;
RrColor *menu_bullet_color;
RrColor *menu_disabled_color;
RrColor *menu_hilite_color;
@ -76,6 +77,9 @@ struct _RrTheme {
RrPixmapMask *close_disabled_mask;
RrPixmapMask *close_pressed_mask;
RrPixmapMask *menu_bullet_mask; /* submenu pointer */
RrPixmapMask *menu_toggle_mask; /* menu boolean */
/* global appearances */
RrAppearance *a_disabled_focused_max;
RrAppearance *a_disabled_unfocused_max;
@ -138,6 +142,7 @@ struct _RrTheme {
RrAppearance *a_menu_item;
RrAppearance *a_menu_disabled;
RrAppearance *a_menu_hilite;
RrAppearance *a_menu_bullet;
RrAppearance *a_clear;
RrAppearance *app_hilite_bg;
@ -145,6 +150,7 @@ struct _RrTheme {
RrAppearance *app_hilite_label;
RrAppearance *app_unhilite_label;
RrAppearance *app_icon;
};
RrTheme *RrThemeNew(const RrInstance *inst, gchar *theme);