#include "client.h"
#include "menu.h"
#include "screen.h"
+#include "prop.h"
#include "actions.h"
+#include "event.h"
#include "grab.h"
#include "openbox.h"
#include "mainloop.h"
#include "render/theme.h"
#define PADDING 2
-#define SEPARATOR_HEIGHT 3
#define MAX_MENU_WIDTH 400
#define ITEM_HEIGHT (ob_rr_theme->menu_font_height + 2*PADDING)
ButtonPressMask | ButtonReleaseMask)
GList *menu_frame_visible;
+GHashTable *menu_frame_map;
+
+static RrAppearance *a_sep;
static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
ObMenuFrame *frame);
static gboolean menu_entry_frame_submenu_timeout(gpointer data);
static void menu_frame_hide(ObMenuFrame *self);
+static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data);
+
static Window createWindow(Window parent, gulong mask,
XSetWindowAttributes *attrib)
{
RrVisual(ob_rr_inst), mask, attrib);
}
-GHashTable *menu_frame_map;
-
void menu_frame_startup(gboolean reconfig)
{
+ gint i;
+
+ a_sep = RrAppearanceCopy(ob_rr_theme->a_clear);
+ RrAppearanceAddTextures(a_sep, ob_rr_theme->menu_sep_width);
+ for (i = 0; i < ob_rr_theme->menu_sep_width; ++i) {
+ a_sep->texture[i].type = RR_TEXTURE_LINE_ART;
+ a_sep->texture[i].data.lineart.color =
+ ob_rr_theme->menu_sep_color;
+ }
+
if (reconfig) return;
menu_frame_map = g_hash_table_new(g_int_hash, g_int_equal);
void menu_frame_shutdown(gboolean reconfig)
{
+ RrAppearanceFree(a_sep);
+
if (reconfig) return;
g_hash_table_destroy(menu_frame_map);
self->window = createWindow(RootWindow(ob_display, ob_screen),
CWEventMask, &attr);
+ /* make it a popup menu type window */
+ PROP_SET32(self->window, net_wm_window_type, atom,
+ prop_atoms.net_wm_window_type_popup_menu);
+
XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->mbwidth);
XSetWindowBorder(ob_display, self->window,
RrColorPixel(ob_rr_theme->menu_border_color));
void menu_frame_move(ObMenuFrame *self, gint x, gint y)
{
RECT_SET_POINT(self->area, x, y);
+ self->monitor = screen_find_monitor_point(x, y);
XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
}
*dx = *dy = 0;
- a = screen_physical_area_monitor(self->monitor);
+ a = screen_physical_area_monitor(screen_find_monitor_point(x, y));
half = g_list_length(self->entries) / 2;
pos = g_list_index(self->entries, self->selected);
th = ob_rr_theme->menu_title_height;
} else {
item_a = ob_rr_theme->a_menu_normal;
- th = SEPARATOR_HEIGHT + 2*PADDING;
+ th = ob_rr_theme->menu_sep_width +
+ 2*ob_rr_theme->menu_sep_paddingy;
}
break;
default:
g_assert_not_reached();
}
+
RECT_SET_SIZE(self->area, self->frame->inner_w, th);
XResizeWindow(ob_display, self->window,
self->area.width, self->area.height);
ob_rr_theme->menu_title_height -
2*ob_rr_theme->paddingy);
} else {
- RrAppearance *clear;
-
- /* unlabeled separaator */
- XMoveResizeWindow(ob_display, self->text, PADDING, PADDING,
- self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
-
- clear = ob_rr_theme->a_clear_tex;
- clear->texture[0].type = RR_TEXTURE_LINE_ART;
- clear->surface.parent = item_a;
- clear->surface.parentx = PADDING;
- clear->surface.parenty = PADDING;
- clear->texture[0].data.lineart.color =
- text_a->texture[0].data.text.color;
- clear->texture[0].data.lineart.x1 = 2*PADDING;
- clear->texture[0].data.lineart.y1 = SEPARATOR_HEIGHT/2;
- clear->texture[0].data.lineart.x2 = self->area.width - 4*PADDING;
- clear->texture[0].data.lineart.y2 = SEPARATOR_HEIGHT/2;
- RrPaint(clear, self->text,
- self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
+ gint i;
+
+ /* unlabeled separator */
+ XMoveResizeWindow(ob_display, self->text, 0, 0,
+ self->area.width,
+ ob_rr_theme->menu_sep_width +
+ 2*ob_rr_theme->menu_sep_paddingy);
+
+ a_sep->surface.parent = item_a;
+ a_sep->surface.parentx = 0;
+ a_sep->surface.parenty = 0;
+ for (i = 0; i < ob_rr_theme->menu_sep_width; ++i) {
+ a_sep->texture[i].data.lineart.x1 =
+ ob_rr_theme->menu_sep_paddingx;
+ a_sep->texture[i].data.lineart.y1 =
+ ob_rr_theme->menu_sep_paddingy + i;
+ a_sep->texture[i].data.lineart.x2 =
+ self->area.width - ob_rr_theme->menu_sep_paddingx - 1;
+ a_sep->texture[i].data.lineart.y2 =
+ ob_rr_theme->menu_sep_paddingy + i;
+ }
+
+ RrPaint(a_sep, self->text, self->area.width,
+ ob_rr_theme->menu_sep_width +
+ 2*ob_rr_theme->menu_sep_paddingy);
}
break;
}
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
- self->entry->data.normal.icon_data)
+ self->entry->data.normal.icon)
{
RrAppearance *clear;
- frame->item_margin.bottom);
clear = ob_rr_theme->a_clear_tex;
- clear->texture[0].type = RR_TEXTURE_RGBA;
- clear->texture[0].data.rgba.width =
- self->entry->data.normal.icon_width;
- clear->texture[0].data.rgba.height =
- self->entry->data.normal.icon_height;
- clear->texture[0].data.rgba.alpha =
+ RrAppearanceClearTextures(clear);
+ clear->texture[0].type = RR_TEXTURE_IMAGE;
+ clear->texture[0].data.image.image =
+ self->entry->data.normal.icon;
+ clear->texture[0].data.image.alpha =
self->entry->data.normal.icon_alpha;
- clear->texture[0].data.rgba.data =
- self->entry->data.normal.icon_data;
clear->surface.parent = item_a;
clear->surface.parentx = PADDING;
clear->surface.parenty = frame->item_margin.top;
- frame->item_margin.bottom);
clear = ob_rr_theme->a_clear_tex;
+ RrAppearanceClearTextures(clear);
clear->texture[0].type = RR_TEXTURE_MASK;
clear->texture[0].data.mask.mask =
self->entry->data.normal.mask;
if (last_entry)
h -= ob_rr_theme->mbwidth;
} else {
- h += SEPARATOR_HEIGHT;
+ h += ob_rr_theme->menu_sep_width +
+ 2*ob_rr_theme->menu_sep_paddingy - PADDING * 2;
}
break;
}
XSetWindowBorder(ob_display, e->window,
RrColorPixel(ob_rr_theme->menu_border_color));
-
text_a = (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
!e->entry->data.normal.enabled ?
/* disabled */
tw = MIN(tw, MAX_MENU_WIDTH);
th = ob_rr_theme->menu_font_height;
- if (e->entry->data.normal.icon_data ||
+ if (e->entry->data.normal.icon ||
e->entry->data.normal.mask)
has_icon = TRUE;
break;
tw = MIN(tw, MAX_MENU_WIDTH);
th = ob_rr_theme->menu_font_height;
- if (e->entry->data.normal.icon_data ||
+ if (e->entry->data.normal.icon ||
e->entry->data.normal.mask)
has_icon = TRUE;
(ob_rr_theme->mbwidth - PADDING) *2;
} else {
tw = 0;
- th = SEPARATOR_HEIGHT;
+ th = ob_rr_theme->menu_sep_width +
+ 2*ob_rr_theme->menu_sep_paddingy - 2*PADDING;
}
break;
}
gboolean mouse)
{
gint px, py;
- guint i;
if (menu_frame_is_visible(self))
return TRUE;
if (!menu_frame_show(self))
return FALSE;
- /* find the monitor the menu is on */
- for (i = 0; i < screen_num_monitors; ++i) {
- Rect *a = screen_physical_area_monitor(i);
- gboolean contains = RECT_CONTAINS(*a, x, y);
- g_free(a);
- if (contains) {
- self->monitor = i;
- break;
- }
- }
-
if (self->menu->place_func)
self->menu->place_func(self, &x, &y, mouse, self->menu->data);
else
return TRUE;
}
+static void remove_submenu_hide_timeout(ObMenuFrame *self /* parent of submenu to hide */)
+{
+ ob_main_loop_timeout_remove(ob_main_loop,
+ menu_entry_frame_submenu_hide_timeout);
+ if (self)
+ self->submenu_to_hide = NULL;
+}
+
gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent,
ObMenuEntryFrame *parent_entry)
{
self->parent = parent;
self->parent_entry = parent_entry;
+ remove_submenu_hide_timeout(parent);
+
/* set up parent's child to be us */
- if (parent->child)
- menu_frame_hide(parent->child);
- parent->child = self;
+ if ((parent->child) != self) {
+ if (parent->child)
+ menu_frame_hide(parent->child);
+ parent->child = self;
+ }
if (!menu_frame_show(self))
return FALSE;
static void menu_frame_hide(ObMenuFrame *self)
{
GList *it = g_list_find(menu_frame_visible, self);
+ gulong ignore_start;
+
+ remove_submenu_hide_timeout(self->parent);
if (!it)
return;
ungrab_keyboard();
}
+ ignore_start = event_start_ignore_all_enters();
XUnmapWindow(ob_display, self->window);
+ event_end_ignore_all_enters(ignore_start);
menu_frame_free(self);
}
}
}
-
ObMenuFrame* menu_frame_under(gint x, gint y)
{
ObMenuFrame *ret = NULL;
return FALSE;
}
+static gboolean menu_entry_frame_submenu_hide_timeout(gpointer data)
+{
+ menu_frame_hide((ObMenuFrame*)data);
+ return FALSE;
+}
+
void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry,
gboolean immediate)
{
ObMenuEntryFrame *old = self->selected;
ObMenuFrame *oldchild = self->child;
+ ObMenuEntryFrame *temp;
+ gboolean reselection;
+
+
+ if (!oldchild) {
+ /* self is the last visible (sub)menu */
+ if (self->parent && self->parent_entry != self->parent->selected) {
+ /* Legend:
+ (config_submenu_hide_delay != 0)
+ In the parent menu corresponding entry "A" selected,
+ this submenu ('self') shown, cursor moved in the parent
+ menu to another entry "B", then cursor moved for the
+ first time into this submenu.
+ Results:
+ parent menu selection is "B" instead of "A",
+ */
+ temp = self->parent->selected;
+ self->parent->selected = self->parent_entry;
+ if (temp)
+ menu_entry_frame_render(temp);
+ menu_entry_frame_render(self->parent_entry);
+ }
+ remove_submenu_hide_timeout(self->parent);
+ }
+ else if (oldchild->child) {
+ /* self is the (at least) grandparent of the last visible submenu */
+ menu_frame_hide(oldchild->child);
+ if (temp = oldchild->selected) {
+ oldchild->selected = NULL;
+ menu_entry_frame_render(temp);
+ }
+ }
+
if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
entry = old;
if (old)
menu_entry_frame_render(old);
- if (oldchild)
- menu_frame_hide(oldchild);
+
+ reselection = FALSE;
+ if (oldchild) {
+ if (self->submenu_to_hide == entry) {
+ /* Legend:
+ (config_submenu_hide_delay != 0)
+ Some entry "A" selected; corresponding submenu shown;
+ cursor moved to another entry "B" and moved back
+ to the entry "A", when submenu hide request added,
+ but submenu not hided.
+ */
+ reselection = TRUE;
+ remove_submenu_hide_timeout(self);
+ }
+ else if (!immediate && config_submenu_hide_delay) {
+ if (self->submenu_to_hide == NULL) {
+ ob_main_loop_timeout_add(ob_main_loop,
+ config_submenu_hide_delay * 1000,
+ menu_entry_frame_submenu_hide_timeout,
+ oldchild, g_direct_equal,
+ NULL);
+ self->submenu_to_hide = old;
+ }
+ }
+ else
+ menu_frame_hide(oldchild);
+ }
if (self->selected) {
menu_entry_frame_render(self->selected);
- if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
+ if (!reselection &&
+ (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU))
+ {
if (config_submenu_show_delay && !immediate) {
/* initiate a new submenu open request */
ob_main_loop_timeout_add(ob_main_loop,