2003-09-17 07:44:49 +00:00
|
|
|
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
|
2003-09-17 07:32:52 +00:00
|
|
|
|
|
|
|
menuframe.c for the Openbox window manager
|
2006-08-22 16:37:35 +00:00
|
|
|
Copyright (c) 2006 Mikael Magnusson
|
2007-04-22 00:36:54 +00:00
|
|
|
Copyright (c) 2003-2007 Dana Jansens
|
2003-09-17 07:32:52 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
#include "menuframe.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "screen.h"
|
|
|
|
#include "grab.h"
|
|
|
|
#include "openbox.h"
|
2006-08-19 05:05:36 +00:00
|
|
|
#include "mainloop.h"
|
2004-03-21 12:10:10 +00:00
|
|
|
#include "config.h"
|
2003-08-28 02:10:23 +00:00
|
|
|
#include "render/theme.h"
|
|
|
|
|
2003-08-30 18:16:36 +00:00
|
|
|
#define PADDING 2
|
2003-08-31 17:04:23 +00:00
|
|
|
#define SEPARATOR_HEIGHT 3
|
2003-09-03 07:24:39 +00:00
|
|
|
#define MAX_MENU_WIDTH 400
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2007-04-24 01:16:33 +00:00
|
|
|
#define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
|
|
|
|
LeaveWindowMask)
|
2003-08-28 02:10:23 +00:00
|
|
|
#define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
|
|
|
|
ButtonPressMask | ButtonReleaseMask)
|
|
|
|
|
|
|
|
GList *menu_frame_visible;
|
|
|
|
|
2003-08-28 17:05:44 +00:00
|
|
|
static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
|
|
|
|
ObMenuFrame *frame);
|
|
|
|
static void menu_entry_frame_free(ObMenuEntryFrame *self);
|
2003-08-28 02:10:23 +00:00
|
|
|
static void menu_frame_render(ObMenuFrame *self);
|
|
|
|
static void menu_frame_update(ObMenuFrame *self);
|
2006-04-22 19:21:06 +00:00
|
|
|
static gboolean menu_entry_frame_submenu_timeout(gpointer data);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-10-15 03:59:35 +00:00
|
|
|
static Window createWindow(Window parent, gulong mask,
|
2004-03-21 01:03:00 +00:00
|
|
|
XSetWindowAttributes *attrib)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
|
|
|
return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
|
2004-03-21 01:03:00 +00:00
|
|
|
RrDepth(ob_rr_inst), InputOutput,
|
2003-08-28 02:10:23 +00:00
|
|
|
RrVisual(ob_rr_inst), mask, attrib);
|
|
|
|
}
|
|
|
|
|
2007-04-22 00:36:54 +00:00
|
|
|
GHashTable *menu_frame_map;
|
|
|
|
|
|
|
|
void menu_frame_startup(gboolean reconfig)
|
|
|
|
{
|
|
|
|
if (reconfig) return;
|
|
|
|
|
|
|
|
menu_frame_map = g_hash_table_new(g_int_hash, g_int_equal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_shutdown(gboolean reconfig)
|
|
|
|
{
|
|
|
|
if (reconfig) return;
|
|
|
|
|
|
|
|
g_hash_table_destroy(menu_frame_map);
|
|
|
|
}
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
|
|
|
|
{
|
|
|
|
ObMenuFrame *self;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
|
|
|
|
self = g_new0(ObMenuFrame, 1);
|
|
|
|
self->type = Window_Menu;
|
|
|
|
self->menu = menu;
|
|
|
|
self->selected = NULL;
|
|
|
|
self->client = client;
|
2007-03-25 16:34:26 +00:00
|
|
|
self->direction_right = TRUE;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
attr.event_mask = FRAME_EVENTMASK;
|
|
|
|
self->window = createWindow(RootWindow(ob_display, ob_screen),
|
2007-03-02 22:06:13 +00:00
|
|
|
CWEventMask, &attr);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
|
|
|
|
self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
|
|
|
|
|
2003-08-28 05:44:13 +00:00
|
|
|
stacking_add(MENU_AS_WINDOW(self));
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_free(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
if (self) {
|
2003-08-28 17:05:44 +00:00
|
|
|
while (self->entries) {
|
|
|
|
menu_entry_frame_free(self->entries->data);
|
|
|
|
self->entries = g_list_delete_link(self->entries, self->entries);
|
|
|
|
}
|
|
|
|
|
2003-08-28 05:44:13 +00:00
|
|
|
stacking_remove(MENU_AS_WINDOW(self));
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
XDestroyWindow(ob_display, self->window);
|
|
|
|
|
|
|
|
RrAppearanceFree(self->a_items);
|
|
|
|
RrAppearanceFree(self->a_title);
|
|
|
|
|
|
|
|
g_free(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-28 17:05:44 +00:00
|
|
|
static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
|
|
|
|
ObMenuFrame *frame)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
|
|
|
ObMenuEntryFrame *self;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
|
|
|
|
self = g_new0(ObMenuEntryFrame, 1);
|
|
|
|
self->entry = entry;
|
|
|
|
self->frame = frame;
|
|
|
|
|
|
|
|
attr.event_mask = ENTRY_EVENTMASK;
|
2007-04-22 00:36:54 +00:00
|
|
|
self->window = createWindow(self->frame->window, CWEventMask, &attr);
|
2003-08-28 02:10:23 +00:00
|
|
|
self->text = createWindow(self->window, 0, NULL);
|
2007-04-22 00:36:54 +00:00
|
|
|
g_hash_table_insert(menu_frame_map, &self->window, self);
|
|
|
|
g_hash_table_insert(menu_frame_map, &self->text, self);
|
|
|
|
if (entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
|
2003-09-01 02:30:12 +00:00
|
|
|
self->icon = createWindow(self->window, 0, NULL);
|
2007-04-22 00:36:54 +00:00
|
|
|
g_hash_table_insert(menu_frame_map, &self->icon, self);
|
|
|
|
}
|
|
|
|
if (entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
|
2003-09-01 02:30:12 +00:00
|
|
|
self->bullet = createWindow(self->window, 0, NULL);
|
2007-04-22 00:36:54 +00:00
|
|
|
g_hash_table_insert(menu_frame_map, &self->bullet, self);
|
2003-09-01 02:30:12 +00:00
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
XMapWindow(ob_display, self->window);
|
|
|
|
XMapWindow(ob_display, self->text);
|
|
|
|
|
2003-09-02 18:53:08 +00:00
|
|
|
self->a_normal = RrAppearanceCopy(ob_rr_theme->a_menu_normal);
|
2003-08-28 02:10:23 +00:00
|
|
|
self->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
|
2003-09-01 07:03:04 +00:00
|
|
|
self->a_selected = RrAppearanceCopy(ob_rr_theme->a_menu_selected);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-31 17:04:23 +00:00
|
|
|
if (entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR) {
|
|
|
|
self->a_separator = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
|
|
|
|
self->a_separator->texture[0].type = RR_TEXTURE_LINE_ART;
|
|
|
|
} else {
|
|
|
|
self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
|
|
|
|
self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
|
|
|
|
self->a_mask = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
|
|
|
|
self->a_mask->texture[0].type = RR_TEXTURE_MASK;
|
2003-09-02 18:53:08 +00:00
|
|
|
self->a_bullet_normal =
|
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_bullet_normal);
|
|
|
|
self->a_bullet_selected =
|
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_bullet_selected);
|
2003-08-31 17:04:23 +00:00
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
self->a_text_normal =
|
2003-09-02 18:53:08 +00:00
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_text_normal);
|
2003-08-28 02:10:23 +00:00
|
|
|
self->a_text_disabled =
|
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_text_disabled);
|
|
|
|
self->a_text_selected =
|
2003-09-01 07:03:04 +00:00
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_text_selected);
|
2007-04-22 03:54:43 +00:00
|
|
|
self->a_text_title =
|
|
|
|
RrAppearanceCopy(ob_rr_theme->a_menu_text_title);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-08-28 17:05:44 +00:00
|
|
|
static void menu_entry_frame_free(ObMenuEntryFrame *self)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
|
|
|
if (self) {
|
|
|
|
XDestroyWindow(ob_display, self->text);
|
|
|
|
XDestroyWindow(ob_display, self->window);
|
2007-04-23 01:54:35 +00:00
|
|
|
g_hash_table_remove(menu_frame_map, &self->text);
|
|
|
|
g_hash_table_remove(menu_frame_map, &self->window);
|
2007-04-22 00:36:54 +00:00
|
|
|
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
|
2003-09-01 02:30:12 +00:00
|
|
|
XDestroyWindow(ob_display, self->icon);
|
2007-04-23 01:54:35 +00:00
|
|
|
g_hash_table_remove(menu_frame_map, &self->icon);
|
2007-04-22 00:36:54 +00:00
|
|
|
}
|
|
|
|
if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
|
2003-09-01 02:30:12 +00:00
|
|
|
XDestroyWindow(ob_display, self->bullet);
|
2007-04-23 01:54:35 +00:00
|
|
|
g_hash_table_remove(menu_frame_map, &self->bullet);
|
2003-09-01 02:30:12 +00:00
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
RrAppearanceFree(self->a_normal);
|
|
|
|
RrAppearanceFree(self->a_disabled);
|
|
|
|
RrAppearanceFree(self->a_selected);
|
|
|
|
|
2003-08-31 17:04:23 +00:00
|
|
|
RrAppearanceFree(self->a_separator);
|
2003-08-28 02:10:23 +00:00
|
|
|
RrAppearanceFree(self->a_icon);
|
2003-08-30 19:03:06 +00:00
|
|
|
RrAppearanceFree(self->a_mask);
|
2003-08-28 02:10:23 +00:00
|
|
|
RrAppearanceFree(self->a_text_normal);
|
|
|
|
RrAppearanceFree(self->a_text_disabled);
|
|
|
|
RrAppearanceFree(self->a_text_selected);
|
2007-04-22 03:54:43 +00:00
|
|
|
RrAppearanceFree(self->a_text_title);
|
2003-09-02 18:53:08 +00:00
|
|
|
RrAppearanceFree(self->a_bullet_normal);
|
|
|
|
RrAppearanceFree(self->a_bullet_selected);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
g_free(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_move(ObMenuFrame *self, gint x, gint y)
|
|
|
|
{
|
|
|
|
RECT_SET_POINT(self->area, x, y);
|
|
|
|
XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
|
|
|
|
}
|
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
static void menu_frame_place_topmenu(ObMenuFrame *self, gint *x, gint *y)
|
2007-03-25 16:34:26 +00:00
|
|
|
{
|
2007-04-26 05:08:33 +00:00
|
|
|
gint dx, dy;
|
|
|
|
|
|
|
|
if (config_menu_middle) {
|
|
|
|
gint myx;
|
|
|
|
|
|
|
|
myx = *x;
|
|
|
|
*y -= self->area.height / 2;
|
|
|
|
|
|
|
|
/* try to the right of the cursor */
|
|
|
|
menu_frame_move_on_screen(self, myx, *y, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = TRUE;
|
2007-04-26 05:08:33 +00:00
|
|
|
if (dx != 0) {
|
|
|
|
/* try to the left of the cursor */
|
|
|
|
myx = *x - self->area.width;
|
|
|
|
menu_frame_move_on_screen(self, myx, *y, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = FALSE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
if (dx != 0) {
|
|
|
|
/* if didnt fit on either side so just use what it says */
|
|
|
|
myx = *x;
|
|
|
|
menu_frame_move_on_screen(self, myx, *y, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = TRUE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
*x = myx + dx;
|
|
|
|
*y += dy;
|
2007-03-25 16:34:26 +00:00
|
|
|
} else {
|
2007-04-26 05:08:33 +00:00
|
|
|
gint myx, myy;
|
|
|
|
|
|
|
|
myx = *x;
|
|
|
|
myy = *y;
|
|
|
|
|
|
|
|
/* try to the bottom right of the cursor */
|
2007-04-26 05:59:37 +00:00
|
|
|
menu_frame_move_on_screen(self, myx, myy, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = TRUE;
|
2007-04-26 05:08:33 +00:00
|
|
|
if (dx != 0 || dy != 0) {
|
|
|
|
/* try to the bottom left of the cursor */
|
|
|
|
myx = *x - self->area.width;
|
|
|
|
myy = *y;
|
2007-04-26 05:59:37 +00:00
|
|
|
menu_frame_move_on_screen(self, myx, myy, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = FALSE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
if (dx != 0 || dy != 0) {
|
|
|
|
/* try to the top right of the cursor */
|
|
|
|
myx = *x;
|
|
|
|
myy = *y - self->area.height;
|
2007-04-26 05:59:37 +00:00
|
|
|
menu_frame_move_on_screen(self, myx, myy, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = TRUE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
if (dx != 0 || dy != 0) {
|
|
|
|
/* try to the top left of the cursor */
|
|
|
|
myx = *x - self->area.width;
|
|
|
|
myy = *y - self->area.height;
|
2007-04-26 05:59:37 +00:00
|
|
|
menu_frame_move_on_screen(self, myx, myy, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = FALSE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
if (dx != 0 || dy != 0) {
|
|
|
|
/* if didnt fit on either side so just use what it says */
|
|
|
|
myx = *x;
|
|
|
|
myy = *y;
|
2007-04-26 05:59:37 +00:00
|
|
|
menu_frame_move_on_screen(self, myx, myy, &dx, &dy);
|
2007-05-02 02:18:37 +00:00
|
|
|
self->direction_right = TRUE;
|
2007-04-26 05:08:33 +00:00
|
|
|
}
|
|
|
|
*x = myx + dx;
|
|
|
|
*y = myy + dy;
|
2007-03-25 16:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
static void menu_frame_place_submenu(ObMenuFrame *self, gint *x, gint *y)
|
2007-03-25 16:34:26 +00:00
|
|
|
{
|
|
|
|
gint overlap;
|
|
|
|
gint bwidth;
|
|
|
|
|
2007-03-25 17:26:22 +00:00
|
|
|
overlap = ob_rr_theme->menu_overlap;
|
2007-03-25 16:34:26 +00:00
|
|
|
bwidth = ob_rr_theme->mbwidth;
|
|
|
|
|
|
|
|
if (self->direction_right)
|
2007-04-26 05:08:33 +00:00
|
|
|
*x = self->parent->area.x + self->parent->area.width -
|
|
|
|
overlap - bwidth;
|
2007-03-25 16:34:26 +00:00
|
|
|
else
|
2007-04-26 05:08:33 +00:00
|
|
|
*x = self->parent->area.x - self->area.width + overlap + bwidth;
|
2007-03-25 16:34:26 +00:00
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
*y = self->parent->area.y + self->parent_entry->area.y;
|
2007-03-25 16:34:26 +00:00
|
|
|
if (config_menu_middle)
|
2007-04-26 05:08:33 +00:00
|
|
|
*y -= (self->area.height - (bwidth * 2) - self->item_h) / 2;
|
2007-03-25 17:26:22 +00:00
|
|
|
else
|
2007-04-26 05:08:33 +00:00
|
|
|
*y += overlap;
|
2007-03-25 16:34:26 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
void menu_frame_move_on_screen(ObMenuFrame *self, gint x, gint y,
|
|
|
|
gint *dx, gint *dy)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
2003-09-25 22:00:07 +00:00
|
|
|
Rect *a = NULL;
|
2003-09-10 18:00:08 +00:00
|
|
|
gint pos, half;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2007-03-25 16:34:26 +00:00
|
|
|
*dx = *dy = 0;
|
|
|
|
|
2005-09-14 17:05:53 +00:00
|
|
|
a = screen_physical_area_monitor(self->monitor);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-09-10 18:00:08 +00:00
|
|
|
half = g_list_length(self->entries) / 2;
|
|
|
|
pos = g_list_index(self->entries, self->selected);
|
|
|
|
|
2007-03-25 16:34:26 +00:00
|
|
|
/* if in the bottom half then check this stuff first, will keep the bottom
|
2003-09-10 18:00:08 +00:00
|
|
|
edge of the menu visible */
|
|
|
|
if (pos > half) {
|
2007-04-26 05:08:33 +00:00
|
|
|
*dx = MAX(*dx, a->x - x);
|
|
|
|
*dy = MAX(*dy, a->y - y);
|
2003-09-10 18:00:08 +00:00
|
|
|
}
|
2007-04-26 05:08:33 +00:00
|
|
|
*dx = MIN(*dx, (a->x + a->width) - (x + self->area.width));
|
|
|
|
*dy = MIN(*dy, (a->y + a->height) - (y + self->area.height));
|
2007-03-25 16:34:26 +00:00
|
|
|
/* if in the top half then check this stuff last, will keep the top
|
2003-09-10 18:00:08 +00:00
|
|
|
edge of the menu visible */
|
|
|
|
if (pos <= half) {
|
2007-04-26 05:08:33 +00:00
|
|
|
*dx = MAX(*dx, a->x - x);
|
|
|
|
*dy = MAX(*dy, a->y - y);
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_entry_frame_render(ObMenuEntryFrame *self)
|
|
|
|
{
|
|
|
|
RrAppearance *item_a, *text_a;
|
|
|
|
gint th; /* temp */
|
2003-08-28 07:49:57 +00:00
|
|
|
ObMenu *sub;
|
2003-09-03 09:12:42 +00:00
|
|
|
ObMenuFrame *frame = self->frame;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
switch (self->entry->type) {
|
|
|
|
case OB_MENU_ENTRY_TYPE_NORMAL:
|
|
|
|
case OB_MENU_ENTRY_TYPE_SUBMENU:
|
2007-04-22 00:36:54 +00:00
|
|
|
item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
!self->entry->data.normal.enabled) ?
|
|
|
|
self->a_disabled :
|
|
|
|
(self == self->frame->selected ?
|
|
|
|
self->a_selected :
|
|
|
|
self->a_normal));
|
2003-08-28 02:10:23 +00:00
|
|
|
th = self->frame->item_h;
|
|
|
|
break;
|
|
|
|
case OB_MENU_ENTRY_TYPE_SEPARATOR:
|
2007-04-22 00:36:54 +00:00
|
|
|
if (self->entry->data.separator.label) {
|
|
|
|
item_a = self->frame->a_title;
|
2007-04-22 03:54:43 +00:00
|
|
|
th = ob_rr_theme->menu_title_height;
|
2007-04-22 00:36:54 +00:00
|
|
|
} else {
|
|
|
|
item_a = self->a_normal;
|
|
|
|
th = SEPARATOR_HEIGHT + 2*PADDING;
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
2007-03-02 02:23:00 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
RECT_SET_SIZE(self->area, self->frame->inner_w, th);
|
|
|
|
XResizeWindow(ob_display, self->window,
|
|
|
|
self->area.width, self->area.height);
|
|
|
|
item_a->surface.parent = self->frame->a_items;
|
|
|
|
item_a->surface.parentx = self->area.x;
|
|
|
|
item_a->surface.parenty = self->area.y;
|
|
|
|
RrPaint(item_a, self->window, self->area.width, self->area.height);
|
|
|
|
|
|
|
|
switch (self->entry->type) {
|
|
|
|
case OB_MENU_ENTRY_TYPE_NORMAL:
|
2007-04-22 00:36:54 +00:00
|
|
|
text_a = (!self->entry->data.normal.enabled ?
|
|
|
|
self->a_text_disabled :
|
|
|
|
(self == self->frame->selected ?
|
|
|
|
self->a_text_selected :
|
|
|
|
self->a_text_normal));
|
2003-08-28 02:10:23 +00:00
|
|
|
text_a->texture[0].data.text.string = self->entry->data.normal.label;
|
2007-04-25 18:26:02 +00:00
|
|
|
if (self->entry->data.normal.shortcut &&
|
|
|
|
(self->frame->menu->show_all_shortcuts ||
|
|
|
|
self->entry->data.normal.shortcut_position > 0))
|
2007-04-25 01:33:20 +00:00
|
|
|
{
|
2007-04-25 18:04:15 +00:00
|
|
|
text_a->texture[0].data.text.shortcut = TRUE;
|
|
|
|
text_a->texture[0].data.text.shortcut_pos =
|
|
|
|
self->entry->data.normal.shortcut_position;
|
2007-04-25 01:33:20 +00:00
|
|
|
} else
|
2007-04-25 18:04:15 +00:00
|
|
|
text_a->texture[0].data.text.shortcut = FALSE;
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
case OB_MENU_ENTRY_TYPE_SUBMENU:
|
2007-04-22 00:36:54 +00:00
|
|
|
text_a = (self == self->frame->selected ?
|
|
|
|
self->a_text_selected :
|
|
|
|
self->a_text_normal);
|
2003-08-28 07:49:57 +00:00
|
|
|
sub = self->entry->data.submenu.submenu;
|
|
|
|
text_a->texture[0].data.text.string = sub ? sub->title : "";
|
2007-04-25 18:26:02 +00:00
|
|
|
if (sub->shortcut && (self->frame->menu->show_all_shortcuts ||
|
|
|
|
sub->shortcut_position > 0))
|
|
|
|
{
|
2007-04-25 18:04:15 +00:00
|
|
|
text_a->texture[0].data.text.shortcut = TRUE;
|
|
|
|
text_a->texture[0].data.text.shortcut_pos = sub->shortcut_position;
|
2007-04-25 01:33:20 +00:00
|
|
|
} else
|
2007-04-25 18:04:15 +00:00
|
|
|
text_a->texture[0].data.text.shortcut = FALSE;
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
case OB_MENU_ENTRY_TYPE_SEPARATOR:
|
2007-04-22 03:54:43 +00:00
|
|
|
if (self->entry->data.separator.label != NULL)
|
|
|
|
text_a = self->a_text_title;
|
|
|
|
else
|
|
|
|
text_a = self->a_text_normal;
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (self->entry->type) {
|
|
|
|
case OB_MENU_ENTRY_TYPE_NORMAL:
|
|
|
|
XMoveResizeWindow(ob_display, self->text,
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->text_x, PADDING,
|
|
|
|
self->frame->text_w,
|
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-08-28 02:10:23 +00:00
|
|
|
text_a->surface.parent = item_a;
|
|
|
|
text_a->surface.parentx = self->frame->text_x;
|
2003-08-30 18:16:36 +00:00
|
|
|
text_a->surface.parenty = PADDING;
|
|
|
|
RrPaint(text_a, self->text, self->frame->text_w,
|
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
2003-08-29 05:49:30 +00:00
|
|
|
case OB_MENU_ENTRY_TYPE_SUBMENU:
|
|
|
|
XMoveResizeWindow(ob_display, self->text,
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->text_x, PADDING,
|
2003-08-29 05:49:30 +00:00
|
|
|
self->frame->text_w - self->frame->item_h,
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-08-29 05:49:30 +00:00
|
|
|
text_a->surface.parent = item_a;
|
|
|
|
text_a->surface.parentx = self->frame->text_x;
|
2003-08-30 18:16:36 +00:00
|
|
|
text_a->surface.parenty = PADDING;
|
2003-08-29 05:49:30 +00:00
|
|
|
RrPaint(text_a, self->text, self->frame->text_w - self->frame->item_h,
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-08-29 05:49:30 +00:00
|
|
|
break;
|
2003-08-28 02:10:23 +00:00
|
|
|
case OB_MENU_ENTRY_TYPE_SEPARATOR:
|
2007-04-22 03:54:43 +00:00
|
|
|
if (self->entry->data.separator.label != NULL) {
|
|
|
|
/* labeled separator */
|
|
|
|
XMoveResizeWindow(ob_display, self->text,
|
|
|
|
ob_rr_theme->paddingx, ob_rr_theme->paddingy,
|
|
|
|
self->area.width - 2*ob_rr_theme->paddingx,
|
|
|
|
ob_rr_theme->menu_title_height -
|
|
|
|
2*ob_rr_theme->paddingy);
|
|
|
|
text_a->surface.parent = item_a;
|
|
|
|
text_a->surface.parentx = ob_rr_theme->paddingx;
|
|
|
|
text_a->surface.parenty = ob_rr_theme->paddingy;
|
|
|
|
RrPaint(text_a, self->text,
|
|
|
|
self->area.width - 2*ob_rr_theme->paddingx,
|
|
|
|
ob_rr_theme->menu_title_height -
|
|
|
|
2*ob_rr_theme->paddingy);
|
|
|
|
} else {
|
|
|
|
/* unlabeled separaator */
|
2007-04-22 00:36:54 +00:00
|
|
|
XMoveResizeWindow(ob_display, self->text, PADDING, PADDING,
|
|
|
|
self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
|
|
|
|
self->a_separator->surface.parent = item_a;
|
|
|
|
self->a_separator->surface.parentx = PADDING;
|
|
|
|
self->a_separator->surface.parenty = PADDING;
|
|
|
|
self->a_separator->texture[0].data.lineart.color =
|
|
|
|
text_a->texture[0].data.text.color;
|
|
|
|
self->a_separator->texture[0].data.lineart.x1 = 2*PADDING;
|
|
|
|
self->a_separator->texture[0].data.lineart.y1 = SEPARATOR_HEIGHT/2;
|
|
|
|
self->a_separator->texture[0].data.lineart.x2 =
|
|
|
|
self->area.width - 4*PADDING;
|
|
|
|
self->a_separator->texture[0].data.lineart.y2 = SEPARATOR_HEIGHT/2;
|
|
|
|
RrPaint(self->a_separator, self->text,
|
|
|
|
self->area.width - 2*PADDING, SEPARATOR_HEIGHT);
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-22 00:36:54 +00:00
|
|
|
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
2003-08-28 08:08:18 +00:00
|
|
|
self->entry->data.normal.icon_data)
|
|
|
|
{
|
2003-09-03 09:12:42 +00:00
|
|
|
XMoveResizeWindow(ob_display, self->icon,
|
|
|
|
PADDING, frame->item_margin.top,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom);
|
2003-08-28 08:08:18 +00:00
|
|
|
self->a_icon->texture[0].data.rgba.width =
|
|
|
|
self->entry->data.normal.icon_width;
|
|
|
|
self->a_icon->texture[0].data.rgba.height =
|
|
|
|
self->entry->data.normal.icon_height;
|
|
|
|
self->a_icon->texture[0].data.rgba.data =
|
|
|
|
self->entry->data.normal.icon_data;
|
2003-08-28 02:10:23 +00:00
|
|
|
self->a_icon->surface.parent = item_a;
|
2003-08-30 18:16:36 +00:00
|
|
|
self->a_icon->surface.parentx = PADDING;
|
2003-09-03 09:12:42 +00:00
|
|
|
self->a_icon->surface.parenty = frame->item_margin.top;
|
2003-08-28 02:10:23 +00:00
|
|
|
RrPaint(self->a_icon, self->icon,
|
2003-09-03 09:12:42 +00:00
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom);
|
2003-08-28 02:10:23 +00:00
|
|
|
XMapWindow(ob_display, self->icon);
|
2007-04-22 00:36:54 +00:00
|
|
|
} else if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
2003-08-30 19:03:06 +00:00
|
|
|
self->entry->data.normal.mask)
|
|
|
|
{
|
2003-09-02 18:53:08 +00:00
|
|
|
RrColor *c;
|
|
|
|
|
2003-09-03 09:12:42 +00:00
|
|
|
XMoveResizeWindow(ob_display, self->icon,
|
|
|
|
PADDING, frame->item_margin.top,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom);
|
2003-08-30 19:03:06 +00:00
|
|
|
self->a_mask->texture[0].data.mask.mask =
|
|
|
|
self->entry->data.normal.mask;
|
2003-09-02 18:53:08 +00:00
|
|
|
|
|
|
|
c = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
!self->entry->data.normal.enabled) ?
|
|
|
|
self->entry->data.normal.mask_disabled_color :
|
|
|
|
(self == self->frame->selected ?
|
|
|
|
self->entry->data.normal.mask_selected_color :
|
|
|
|
self->entry->data.normal.mask_normal_color));
|
|
|
|
self->a_mask->texture[0].data.mask.color = c;
|
|
|
|
|
2003-08-30 19:03:06 +00:00
|
|
|
self->a_mask->surface.parent = item_a;
|
|
|
|
self->a_mask->surface.parentx = PADDING;
|
2003-09-03 09:12:42 +00:00
|
|
|
self->a_mask->surface.parenty = frame->item_margin.top;
|
2003-08-30 19:03:06 +00:00
|
|
|
RrPaint(self->a_mask, self->icon,
|
2003-09-03 09:12:42 +00:00
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom,
|
|
|
|
self->frame->item_h - frame->item_margin.top
|
|
|
|
- frame->item_margin.bottom);
|
2003-08-30 19:03:06 +00:00
|
|
|
XMapWindow(ob_display, self->icon);
|
2003-08-28 02:10:23 +00:00
|
|
|
} else
|
|
|
|
XUnmapWindow(ob_display, self->icon);
|
|
|
|
|
|
|
|
if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
|
2003-09-02 18:53:08 +00:00
|
|
|
RrAppearance *bullet_a;
|
2003-08-28 02:10:23 +00:00
|
|
|
XMoveResizeWindow(ob_display, self->bullet,
|
2003-08-29 05:49:30 +00:00
|
|
|
self->frame->text_x + self->frame->text_w
|
2003-08-30 18:16:36 +00:00
|
|
|
- self->frame->item_h + PADDING, PADDING,
|
|
|
|
self->frame->item_h - 2*PADDING,
|
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-09-02 18:53:08 +00:00
|
|
|
bullet_a = (self == self->frame->selected ?
|
|
|
|
self->a_bullet_selected :
|
|
|
|
self->a_bullet_normal);
|
|
|
|
bullet_a->surface.parent = item_a;
|
|
|
|
bullet_a->surface.parentx =
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->text_x + self->frame->text_w - self->frame->item_h
|
2003-09-01 16:37:21 +00:00
|
|
|
+ PADDING;
|
2003-09-02 18:53:08 +00:00
|
|
|
bullet_a->surface.parenty = PADDING;
|
|
|
|
RrPaint(bullet_a, self->bullet,
|
2003-08-30 18:16:36 +00:00
|
|
|
self->frame->item_h - 2*PADDING,
|
|
|
|
self->frame->item_h - 2*PADDING);
|
2003-08-28 02:10:23 +00:00
|
|
|
XMapWindow(ob_display, self->bullet);
|
|
|
|
} else
|
|
|
|
XUnmapWindow(ob_display, self->bullet);
|
2003-09-08 09:08:36 +00:00
|
|
|
|
|
|
|
XFlush(ob_display);
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_frame_render(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
gint w = 0, h = 0;
|
|
|
|
gint tw, th; /* temps */
|
|
|
|
GList *it;
|
2003-08-29 05:49:30 +00:00
|
|
|
gboolean has_icon = FALSE;
|
2003-08-28 07:49:57 +00:00
|
|
|
ObMenu *sub;
|
2007-04-22 03:13:41 +00:00
|
|
|
ObMenuEntryFrame *e;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
scary commit..but here goes.
YOUR THEMES ARE NOW OFFICIALLY BROKEN.
Openbox has just moved it's theme format to an XML based one. The details of
this format can be found in data/themerc.xsd (and http://openbox.org/themerc.xsd
ALSO! This is very good and important and stuff! In the tools directory you
will find THEMETOXML ! This tool takes a themerc on stdin, and spits out
the same theme in theme.xml format. So this is all you need to do to update
your themes.
PLEASE NOTE: This themetoxml does _not_ install itself anywhere. It simply
builds and then lives out in its tools/themetoxml directory, and that's it. So
if you want to use it, that is where to find it.
In moving to the new XML format, a number of additions/changes to the theme
engine have been made. Themetoxml takes these into account and will set all
the new things appropriately to make your theme look the same as it always has.
New additions include..
* padding now has an horizontal and vertical component, instead of being one number
* menus can have different borders than windows (color and size)
* menu offset can now be negative. it's a little weird, but someone will want it no doubt
* fonts are no longer controled by the theme at all, however font shadowing is, and on that note..
* font shadows are now any color you want, not just black and white
* you can now set the shadow anywhere you can set the text's color, so you have more control, i.e. you can set shadow on active menu items but not inactive, or disabled, etc.
* every color now has an alpha channel. at the moment they don't do anything, besides the font shadow one, but it leaves room for future explorations. it is REALLY HIGHLY RECOMMENDED that you set the alpha to 255 all the time, until such time as it could be useful. otherwise one day your theme may turn awful for people.
* font colors are in the range 0-255, in case you were wondering, and they have to be specified in decimal
* if you'd like to change you font's you can do so in your configuration file. this is how it is going to stay. changing the font in the theme assumes too much about peoples eye sight and locality and stuff. it doesn't belong there, sorry. the system-wide default rc.xml includes the new font settings for your viewing pleasure, and ill drop an example of it below.
* shadows can now be positioned in any direction, they have both an x and a y offset which can be negative and positive. and offset of 0,0 will disable the shadow
This isn't a release or anything. If someone had some good ideas about the xml theme format, I'd like to hear them. But I don't think it will be changing much right now beyond where it is. I don't even know how the new functionality will play out for themers, so we'll see.
Whew.. I guess that's it. I'm not sure if I mentioned every little change or not, but oh well. Mileage may vary.. Please send any feedback.
Here's the font configuration example. Hopefully ObConf will let you set this real soon.
<theme>
...
<font place="ActiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="InactiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuTitle">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuItem">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
</theme>
2007-03-05 15:44:17 +00:00
|
|
|
XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->mbwidth);
|
2003-08-28 02:10:23 +00:00
|
|
|
XSetWindowBorder(ob_display, self->window,
|
scary commit..but here goes.
YOUR THEMES ARE NOW OFFICIALLY BROKEN.
Openbox has just moved it's theme format to an XML based one. The details of
this format can be found in data/themerc.xsd (and http://openbox.org/themerc.xsd
ALSO! This is very good and important and stuff! In the tools directory you
will find THEMETOXML ! This tool takes a themerc on stdin, and spits out
the same theme in theme.xml format. So this is all you need to do to update
your themes.
PLEASE NOTE: This themetoxml does _not_ install itself anywhere. It simply
builds and then lives out in its tools/themetoxml directory, and that's it. So
if you want to use it, that is where to find it.
In moving to the new XML format, a number of additions/changes to the theme
engine have been made. Themetoxml takes these into account and will set all
the new things appropriately to make your theme look the same as it always has.
New additions include..
* padding now has an horizontal and vertical component, instead of being one number
* menus can have different borders than windows (color and size)
* menu offset can now be negative. it's a little weird, but someone will want it no doubt
* fonts are no longer controled by the theme at all, however font shadowing is, and on that note..
* font shadows are now any color you want, not just black and white
* you can now set the shadow anywhere you can set the text's color, so you have more control, i.e. you can set shadow on active menu items but not inactive, or disabled, etc.
* every color now has an alpha channel. at the moment they don't do anything, besides the font shadow one, but it leaves room for future explorations. it is REALLY HIGHLY RECOMMENDED that you set the alpha to 255 all the time, until such time as it could be useful. otherwise one day your theme may turn awful for people.
* font colors are in the range 0-255, in case you were wondering, and they have to be specified in decimal
* if you'd like to change you font's you can do so in your configuration file. this is how it is going to stay. changing the font in the theme assumes too much about peoples eye sight and locality and stuff. it doesn't belong there, sorry. the system-wide default rc.xml includes the new font settings for your viewing pleasure, and ill drop an example of it below.
* shadows can now be positioned in any direction, they have both an x and a y offset which can be negative and positive. and offset of 0,0 will disable the shadow
This isn't a release or anything. If someone had some good ideas about the xml theme format, I'd like to hear them. But I don't think it will be changing much right now beyond where it is. I don't even know how the new functionality will play out for themers, so we'll see.
Whew.. I guess that's it. I'm not sure if I mentioned every little change or not, but oh well. Mileage may vary.. Please send any feedback.
Here's the font configuration example. Hopefully ObConf will let you set this real soon.
<theme>
...
<font place="ActiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="InactiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuTitle">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuItem">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
</theme>
2007-03-05 15:44:17 +00:00
|
|
|
RrColorPixel(ob_rr_theme->menu_b_color));
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2007-04-22 00:36:54 +00:00
|
|
|
/* find text dimensions */
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-09-03 09:12:42 +00:00
|
|
|
STRUT_SET(self->item_margin, 0, 0, 0, 0);
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
if (self->entries) {
|
|
|
|
ObMenuEntryFrame *e = self->entries->data;
|
2003-09-03 09:12:42 +00:00
|
|
|
gint l, t, r, b;
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
e->a_text_normal->texture[0].data.text.string = "";
|
2007-05-02 00:35:22 +00:00
|
|
|
RrMinSize(e->a_text_normal, &tw, &th);
|
2003-08-30 18:16:36 +00:00
|
|
|
tw += 2*PADDING;
|
|
|
|
th += 2*PADDING;
|
2003-08-28 02:10:23 +00:00
|
|
|
self->item_h = th;
|
2003-09-03 09:12:42 +00:00
|
|
|
|
|
|
|
RrMargins(e->a_normal, &l, &t, &r, &b);
|
|
|
|
STRUT_SET(self->item_margin,
|
|
|
|
MAX(self->item_margin.left, l),
|
|
|
|
MAX(self->item_margin.top, t),
|
|
|
|
MAX(self->item_margin.right, r),
|
|
|
|
MAX(self->item_margin.bottom, b));
|
|
|
|
RrMargins(e->a_selected, &l, &t, &r, &b);
|
|
|
|
STRUT_SET(self->item_margin,
|
|
|
|
MAX(self->item_margin.left, l),
|
|
|
|
MAX(self->item_margin.top, t),
|
|
|
|
MAX(self->item_margin.right, r),
|
|
|
|
MAX(self->item_margin.bottom, b));
|
|
|
|
RrMargins(e->a_disabled, &l, &t, &r, &b);
|
|
|
|
STRUT_SET(self->item_margin,
|
|
|
|
MAX(self->item_margin.left, l),
|
|
|
|
MAX(self->item_margin.top, t),
|
|
|
|
MAX(self->item_margin.right, r),
|
|
|
|
MAX(self->item_margin.bottom, b));
|
2003-08-28 02:10:23 +00:00
|
|
|
} else
|
|
|
|
self->item_h = 0;
|
|
|
|
|
2007-04-22 00:36:54 +00:00
|
|
|
/* render the entries */
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
for (it = self->entries; it; it = g_list_next(it)) {
|
|
|
|
RrAppearance *text_a;
|
2007-04-22 03:13:41 +00:00
|
|
|
e = it->data;
|
|
|
|
|
|
|
|
/* if the first entry is a labeled separator, then make its border
|
|
|
|
overlap with the menu's outside border */
|
|
|
|
if (it == self->entries &&
|
|
|
|
e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR &&
|
|
|
|
e->entry->data.separator.label)
|
|
|
|
{
|
|
|
|
h -= ob_rr_theme->mbwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR &&
|
|
|
|
e->entry->data.separator.label)
|
|
|
|
{
|
|
|
|
e->border = ob_rr_theme->mbwidth;
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2007-04-22 03:13:41 +00:00
|
|
|
RECT_SET_POINT(e->area, 0, h+e->border);
|
|
|
|
XMoveWindow(ob_display, e->window, e->area.x-e->border, e->area.y-e->border);
|
|
|
|
XSetWindowBorderWidth(ob_display, e->window, e->border);
|
|
|
|
XSetWindowBorder(ob_display, e->window,
|
|
|
|
RrColorPixel(ob_rr_theme->menu_b_color));
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-28 06:32:27 +00:00
|
|
|
text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
!e->entry->data.normal.enabled) ?
|
2003-08-28 02:10:23 +00:00
|
|
|
e->a_text_disabled :
|
|
|
|
(e == self->selected ?
|
|
|
|
e->a_text_selected :
|
|
|
|
e->a_text_normal));
|
|
|
|
switch (e->entry->type) {
|
|
|
|
case OB_MENU_ENTRY_TYPE_NORMAL:
|
|
|
|
text_a->texture[0].data.text.string = e->entry->data.normal.label;
|
2007-05-02 00:35:22 +00:00
|
|
|
RrMinSize(text_a, &tw, &th);
|
2003-09-03 07:24:39 +00:00
|
|
|
tw = MIN(tw, MAX_MENU_WIDTH);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-30 19:03:06 +00:00
|
|
|
if (e->entry->data.normal.icon_data ||
|
|
|
|
e->entry->data.normal.mask)
|
2003-08-28 08:08:18 +00:00
|
|
|
has_icon = TRUE;
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
case OB_MENU_ENTRY_TYPE_SUBMENU:
|
2003-08-28 07:49:57 +00:00
|
|
|
sub = e->entry->data.submenu.submenu;
|
|
|
|
text_a->texture[0].data.text.string = sub ? sub->title : "";
|
2007-05-02 00:35:22 +00:00
|
|
|
RrMinSize(text_a, &tw, &th);
|
2003-09-03 07:24:39 +00:00
|
|
|
tw = MIN(tw, MAX_MENU_WIDTH);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-30 19:03:06 +00:00
|
|
|
if (e->entry->data.normal.icon_data ||
|
|
|
|
e->entry->data.normal.mask)
|
|
|
|
has_icon = TRUE;
|
|
|
|
|
2003-08-30 18:16:36 +00:00
|
|
|
tw += self->item_h - PADDING;
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
case OB_MENU_ENTRY_TYPE_SEPARATOR:
|
2007-04-22 00:36:54 +00:00
|
|
|
if (e->entry->data.separator.label != NULL) {
|
2007-04-22 03:54:43 +00:00
|
|
|
e->a_text_title->texture[0].data.text.string =
|
2007-04-22 00:36:54 +00:00
|
|
|
e->entry->data.separator.label;
|
2007-05-02 00:35:22 +00:00
|
|
|
RrMinSize(e->a_text_title, &tw, &th);
|
2007-04-22 00:36:54 +00:00
|
|
|
tw = MIN(tw, MAX_MENU_WIDTH);
|
2007-04-22 03:54:43 +00:00
|
|
|
th = ob_rr_theme->menu_title_height +
|
|
|
|
(ob_rr_theme->mbwidth - PADDING) *2;
|
2007-04-22 00:36:54 +00:00
|
|
|
} else {
|
|
|
|
tw = 0;
|
|
|
|
th = SEPARATOR_HEIGHT;
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-08-30 18:16:36 +00:00
|
|
|
tw += 2*PADDING;
|
|
|
|
th += 2*PADDING;
|
2003-08-28 02:10:23 +00:00
|
|
|
w = MAX(w, tw);
|
|
|
|
h += th;
|
|
|
|
}
|
|
|
|
|
2007-04-22 03:13:41 +00:00
|
|
|
/* if the last entry is a labeled separator, then make its border
|
|
|
|
overlap with the menu's outside border */
|
|
|
|
it = g_list_last(self->entries);
|
|
|
|
e = it ? it->data : NULL;
|
|
|
|
if (e && e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR &&
|
|
|
|
e->entry->data.separator.label)
|
|
|
|
{
|
|
|
|
h -= ob_rr_theme->mbwidth;
|
|
|
|
}
|
|
|
|
|
2003-08-30 18:16:36 +00:00
|
|
|
self->text_x = PADDING;
|
2003-08-28 02:10:23 +00:00
|
|
|
self->text_w = w;
|
|
|
|
|
|
|
|
if (self->entries) {
|
|
|
|
if (has_icon) {
|
2003-08-30 18:16:36 +00:00
|
|
|
w += self->item_h + PADDING;
|
|
|
|
self->text_x += self->item_h + PADDING;
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w) w = 10;
|
2007-04-22 00:36:54 +00:00
|
|
|
if (!h) h = 3;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
XResizeWindow(ob_display, self->window, w, h);
|
|
|
|
|
|
|
|
self->inner_w = w;
|
|
|
|
|
2007-04-22 00:36:54 +00:00
|
|
|
RrPaint(self->a_items, self->window, w, h);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
for (it = self->entries; it; it = g_list_next(it))
|
|
|
|
menu_entry_frame_render(it->data);
|
|
|
|
|
scary commit..but here goes.
YOUR THEMES ARE NOW OFFICIALLY BROKEN.
Openbox has just moved it's theme format to an XML based one. The details of
this format can be found in data/themerc.xsd (and http://openbox.org/themerc.xsd
ALSO! This is very good and important and stuff! In the tools directory you
will find THEMETOXML ! This tool takes a themerc on stdin, and spits out
the same theme in theme.xml format. So this is all you need to do to update
your themes.
PLEASE NOTE: This themetoxml does _not_ install itself anywhere. It simply
builds and then lives out in its tools/themetoxml directory, and that's it. So
if you want to use it, that is where to find it.
In moving to the new XML format, a number of additions/changes to the theme
engine have been made. Themetoxml takes these into account and will set all
the new things appropriately to make your theme look the same as it always has.
New additions include..
* padding now has an horizontal and vertical component, instead of being one number
* menus can have different borders than windows (color and size)
* menu offset can now be negative. it's a little weird, but someone will want it no doubt
* fonts are no longer controled by the theme at all, however font shadowing is, and on that note..
* font shadows are now any color you want, not just black and white
* you can now set the shadow anywhere you can set the text's color, so you have more control, i.e. you can set shadow on active menu items but not inactive, or disabled, etc.
* every color now has an alpha channel. at the moment they don't do anything, besides the font shadow one, but it leaves room for future explorations. it is REALLY HIGHLY RECOMMENDED that you set the alpha to 255 all the time, until such time as it could be useful. otherwise one day your theme may turn awful for people.
* font colors are in the range 0-255, in case you were wondering, and they have to be specified in decimal
* if you'd like to change you font's you can do so in your configuration file. this is how it is going to stay. changing the font in the theme assumes too much about peoples eye sight and locality and stuff. it doesn't belong there, sorry. the system-wide default rc.xml includes the new font settings for your viewing pleasure, and ill drop an example of it below.
* shadows can now be positioned in any direction, they have both an x and a y offset which can be negative and positive. and offset of 0,0 will disable the shadow
This isn't a release or anything. If someone had some good ideas about the xml theme format, I'd like to hear them. But I don't think it will be changing much right now beyond where it is. I don't even know how the new functionality will play out for themers, so we'll see.
Whew.. I guess that's it. I'm not sure if I mentioned every little change or not, but oh well. Mileage may vary.. Please send any feedback.
Here's the font configuration example. Hopefully ObConf will let you set this real soon.
<theme>
...
<font place="ActiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="InactiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuTitle">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuItem">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
</theme>
2007-03-05 15:44:17 +00:00
|
|
|
w += ob_rr_theme->mbwidth * 2;
|
|
|
|
h += ob_rr_theme->mbwidth * 2;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
RECT_SET_SIZE(self->area, w, h);
|
2003-09-07 19:04:25 +00:00
|
|
|
|
|
|
|
XFlush(ob_display);
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void menu_frame_update(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
GList *mit, *fit;
|
|
|
|
|
2003-08-29 17:17:07 +00:00
|
|
|
menu_pipe_execute(self->menu);
|
2003-08-28 07:49:57 +00:00
|
|
|
menu_find_submenus(self->menu);
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
self->selected = NULL;
|
|
|
|
|
|
|
|
for (mit = self->menu->entries, fit = self->entries; mit && fit;
|
|
|
|
mit = g_list_next(mit), fit = g_list_next(fit))
|
|
|
|
{
|
|
|
|
ObMenuEntryFrame *f = fit->data;
|
|
|
|
f->entry = mit->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (mit) {
|
|
|
|
ObMenuEntryFrame *e = menu_entry_frame_new(mit->data, self);
|
|
|
|
self->entries = g_list_append(self->entries, e);
|
|
|
|
mit = g_list_next(mit);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fit) {
|
|
|
|
GList *n = g_list_next(fit);
|
|
|
|
menu_entry_frame_free(fit->data);
|
|
|
|
self->entries = g_list_delete_link(self->entries, fit);
|
|
|
|
fit = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_frame_render(self);
|
|
|
|
}
|
|
|
|
|
2007-03-25 16:34:26 +00:00
|
|
|
static gboolean menu_frame_is_visible(ObMenuFrame *self)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
2007-03-25 16:34:26 +00:00
|
|
|
return !!(g_list_find(menu_frame_visible, self));
|
|
|
|
}
|
2003-08-28 19:10:36 +00:00
|
|
|
|
2007-03-25 16:34:26 +00:00
|
|
|
static gboolean menu_frame_show(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
GList *it;
|
2003-08-28 19:10:36 +00:00
|
|
|
|
|
|
|
/* determine if the underlying menu is already visible */
|
|
|
|
for (it = menu_frame_visible; it; it = g_list_next(it)) {
|
|
|
|
ObMenuFrame *f = it->data;
|
|
|
|
if (f->menu == self->menu)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!it) {
|
2003-08-28 05:44:13 +00:00
|
|
|
if (self->menu->update_func)
|
2007-05-03 20:39:26 +00:00
|
|
|
if (!self->menu->update_func(self, self->menu->data))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu_frame_visible == NULL) {
|
|
|
|
/* no menus shown yet */
|
|
|
|
if (!grab_pointer(TRUE, TRUE, OB_CURSOR_POINTER))
|
|
|
|
return FALSE;
|
|
|
|
if (!grab_keyboard(TRUE)) {
|
|
|
|
grab_pointer(FALSE, TRUE, OB_CURSOR_POINTER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 19:10:36 +00:00
|
|
|
menu_frame_update(self);
|
|
|
|
|
2003-09-14 21:06:20 +00:00
|
|
|
menu_frame_visible = g_list_prepend(menu_frame_visible, self);
|
2007-03-25 16:34:26 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
gboolean menu_frame_show_topmenu(ObMenuFrame *self, gint x, gint y,
|
|
|
|
gint button)
|
2007-03-25 16:34:26 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (RECT_CONTAINS(*a, x, y)) {
|
|
|
|
self->monitor = i;
|
|
|
|
break;
|
|
|
|
}
|
2006-08-02 17:25:32 +00:00
|
|
|
}
|
2003-09-14 21:06:20 +00:00
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
if (self->menu->place_func)
|
|
|
|
self->menu->place_func(self, &x, &y, button, self->menu->data);
|
|
|
|
else
|
|
|
|
menu_frame_place_topmenu(self, &x, &y);
|
|
|
|
|
|
|
|
menu_frame_move(self, x, y);
|
2007-03-25 16:34:26 +00:00
|
|
|
|
|
|
|
XMapWindow(ob_display, self->window);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean menu_frame_show_submenu(ObMenuFrame *self, ObMenuFrame *parent,
|
|
|
|
ObMenuEntryFrame *parent_entry)
|
|
|
|
{
|
2007-04-22 00:36:54 +00:00
|
|
|
ObMenuEntryFrame *e;
|
2007-04-26 05:08:33 +00:00
|
|
|
gint x, y, dx, dy;
|
2007-03-25 16:34:26 +00:00
|
|
|
|
|
|
|
if (menu_frame_is_visible(self))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
self->monitor = parent->monitor;
|
|
|
|
self->parent = parent;
|
|
|
|
self->parent_entry = parent_entry;
|
|
|
|
|
|
|
|
/* set up parent's child to be us */
|
|
|
|
if (parent->child)
|
|
|
|
menu_frame_hide(parent->child);
|
|
|
|
parent->child = self;
|
|
|
|
|
2007-03-25 16:38:04 +00:00
|
|
|
if (!menu_frame_show(self))
|
|
|
|
return FALSE;
|
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
menu_frame_place_submenu(self, &x, &y);
|
|
|
|
menu_frame_move_on_screen(self, x, y, &dx, &dy);
|
2007-03-25 16:34:26 +00:00
|
|
|
|
2007-04-26 05:08:33 +00:00
|
|
|
if (dx != 0) {
|
|
|
|
/*try the other side */
|
|
|
|
self->direction_right = !self->direction_right;
|
|
|
|
menu_frame_place_submenu(self, &x, &y);
|
|
|
|
menu_frame_move_on_screen(self, x, y, &dx, &dy);
|
2007-03-25 16:34:26 +00:00
|
|
|
}
|
2007-04-26 05:08:33 +00:00
|
|
|
menu_frame_move(self, x + dx, y + dy);
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
XMapWindow(ob_display, self->window);
|
2003-10-11 06:47:11 +00:00
|
|
|
|
2007-04-22 00:53:21 +00:00
|
|
|
if (screen_pointer_pos(&dx, &dy) && (e = menu_entry_frame_under(dx, dy)) &&
|
|
|
|
e->frame == self)
|
2007-04-22 00:36:54 +00:00
|
|
|
++e->ignore_enters;
|
|
|
|
|
2003-10-11 06:47:11 +00:00
|
|
|
return TRUE;
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_hide(ObMenuFrame *self)
|
|
|
|
{
|
2003-08-28 19:10:36 +00:00
|
|
|
GList *it = g_list_find(menu_frame_visible, self);
|
|
|
|
|
|
|
|
if (!it)
|
|
|
|
return;
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
if (self->child)
|
|
|
|
menu_frame_hide(self->child);
|
|
|
|
|
|
|
|
if (self->parent)
|
|
|
|
self->parent->child = NULL;
|
|
|
|
self->parent = NULL;
|
2007-03-25 16:34:26 +00:00
|
|
|
self->parent_entry = NULL;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-30 05:04:08 +00:00
|
|
|
menu_frame_visible = g_list_delete_link(menu_frame_visible, it);
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
if (menu_frame_visible == NULL) {
|
|
|
|
/* last menu shown */
|
2007-04-22 14:07:29 +00:00
|
|
|
grab_pointer(FALSE, TRUE, OB_CURSOR_NONE);
|
2003-08-28 02:10:23 +00:00
|
|
|
grab_keyboard(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
XUnmapWindow(ob_display, self->window);
|
|
|
|
|
|
|
|
menu_frame_free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_hide_all()
|
|
|
|
{
|
2007-03-02 22:11:46 +00:00
|
|
|
GList *it;
|
|
|
|
|
2006-04-22 19:21:06 +00:00
|
|
|
if (config_submenu_show_delay) {
|
|
|
|
/* remove any submenu open requests */
|
|
|
|
ob_main_loop_timeout_remove(ob_main_loop,
|
|
|
|
menu_entry_frame_submenu_timeout);
|
|
|
|
}
|
2007-03-02 22:11:46 +00:00
|
|
|
if ((it = g_list_last(menu_frame_visible)))
|
2003-08-28 05:44:13 +00:00
|
|
|
menu_frame_hide(it->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_hide_all_client(ObClient *client)
|
|
|
|
{
|
|
|
|
GList *it = g_list_last(menu_frame_visible);
|
|
|
|
if (it) {
|
|
|
|
ObMenuFrame *f = it->data;
|
|
|
|
if (f->client == client)
|
|
|
|
menu_frame_hide(f);
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 05:44:13 +00:00
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
ObMenuFrame* menu_frame_under(gint x, gint y)
|
|
|
|
{
|
|
|
|
ObMenuFrame *ret = NULL;
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
for (it = menu_frame_visible; it; it = g_list_next(it)) {
|
|
|
|
ObMenuFrame *f = it->data;
|
|
|
|
|
|
|
|
if (RECT_CONTAINS(f->area, x, y)) {
|
|
|
|
ret = f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
|
|
|
|
{
|
|
|
|
ObMenuFrame *frame;
|
|
|
|
ObMenuEntryFrame *ret = NULL;
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
if ((frame = menu_frame_under(x, y))) {
|
scary commit..but here goes.
YOUR THEMES ARE NOW OFFICIALLY BROKEN.
Openbox has just moved it's theme format to an XML based one. The details of
this format can be found in data/themerc.xsd (and http://openbox.org/themerc.xsd
ALSO! This is very good and important and stuff! In the tools directory you
will find THEMETOXML ! This tool takes a themerc on stdin, and spits out
the same theme in theme.xml format. So this is all you need to do to update
your themes.
PLEASE NOTE: This themetoxml does _not_ install itself anywhere. It simply
builds and then lives out in its tools/themetoxml directory, and that's it. So
if you want to use it, that is where to find it.
In moving to the new XML format, a number of additions/changes to the theme
engine have been made. Themetoxml takes these into account and will set all
the new things appropriately to make your theme look the same as it always has.
New additions include..
* padding now has an horizontal and vertical component, instead of being one number
* menus can have different borders than windows (color and size)
* menu offset can now be negative. it's a little weird, but someone will want it no doubt
* fonts are no longer controled by the theme at all, however font shadowing is, and on that note..
* font shadows are now any color you want, not just black and white
* you can now set the shadow anywhere you can set the text's color, so you have more control, i.e. you can set shadow on active menu items but not inactive, or disabled, etc.
* every color now has an alpha channel. at the moment they don't do anything, besides the font shadow one, but it leaves room for future explorations. it is REALLY HIGHLY RECOMMENDED that you set the alpha to 255 all the time, until such time as it could be useful. otherwise one day your theme may turn awful for people.
* font colors are in the range 0-255, in case you were wondering, and they have to be specified in decimal
* if you'd like to change you font's you can do so in your configuration file. this is how it is going to stay. changing the font in the theme assumes too much about peoples eye sight and locality and stuff. it doesn't belong there, sorry. the system-wide default rc.xml includes the new font settings for your viewing pleasure, and ill drop an example of it below.
* shadows can now be positioned in any direction, they have both an x and a y offset which can be negative and positive. and offset of 0,0 will disable the shadow
This isn't a release or anything. If someone had some good ideas about the xml theme format, I'd like to hear them. But I don't think it will be changing much right now beyond where it is. I don't even know how the new functionality will play out for themers, so we'll see.
Whew.. I guess that's it. I'm not sure if I mentioned every little change or not, but oh well. Mileage may vary.. Please send any feedback.
Here's the font configuration example. Hopefully ObConf will let you set this real soon.
<theme>
...
<font place="ActiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="InactiveWindow">
<name>arial,sans</name>
<size>7</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuTitle">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
<font place="MenuItem">
<name>arial,sans</name>
<size>8</size>
<weight>bold</weight>
<slant>normal</slant>
</font>
</theme>
2007-03-05 15:44:17 +00:00
|
|
|
x -= ob_rr_theme->mbwidth + frame->area.x;
|
2007-04-22 00:36:54 +00:00
|
|
|
y -= ob_rr_theme->mbwidth + frame->area.y;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
|
|
|
for (it = frame->entries; it; it = g_list_next(it)) {
|
|
|
|
ObMenuEntryFrame *e = it->data;
|
|
|
|
|
|
|
|
if (RECT_CONTAINS(e->area, x, y)) {
|
|
|
|
ret = e;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-22 19:21:06 +00:00
|
|
|
static gboolean menu_entry_frame_submenu_timeout(gpointer data)
|
|
|
|
{
|
|
|
|
menu_entry_frame_show_submenu((ObMenuEntryFrame*)data);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-04-25 01:33:20 +00:00
|
|
|
void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry,
|
|
|
|
gboolean immediate)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
|
|
|
ObMenuEntryFrame *old = self->selected;
|
2003-08-28 05:44:13 +00:00
|
|
|
ObMenuFrame *oldchild = self->child;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-31 19:54:34 +00:00
|
|
|
if (entry && entry->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR)
|
|
|
|
entry = old;
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
if (old == entry) return;
|
2006-04-22 19:21:06 +00:00
|
|
|
|
|
|
|
if (config_submenu_show_delay) {
|
|
|
|
/* remove any submenu open requests */
|
|
|
|
ob_main_loop_timeout_remove(ob_main_loop,
|
|
|
|
menu_entry_frame_submenu_timeout);
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-31 19:54:34 +00:00
|
|
|
self->selected = entry;
|
2003-08-28 02:10:23 +00:00
|
|
|
|
2003-08-28 05:44:13 +00:00
|
|
|
if (old)
|
2003-08-28 02:10:23 +00:00
|
|
|
menu_entry_frame_render(old);
|
2003-08-28 05:44:13 +00:00
|
|
|
if (oldchild)
|
|
|
|
menu_frame_hide(oldchild);
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
if (self->selected) {
|
|
|
|
menu_entry_frame_render(self->selected);
|
|
|
|
|
2006-04-22 19:21:06 +00:00
|
|
|
if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
|
2007-04-25 01:33:20 +00:00
|
|
|
if (config_submenu_show_delay && !immediate) {
|
2006-04-22 19:21:06 +00:00
|
|
|
/* initiate a new submenu open request */
|
|
|
|
ob_main_loop_timeout_add(ob_main_loop,
|
|
|
|
config_submenu_show_delay * 1000,
|
|
|
|
menu_entry_frame_submenu_timeout,
|
2007-04-22 04:16:00 +00:00
|
|
|
self->selected, g_direct_equal,
|
2006-04-22 19:21:06 +00:00
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
menu_entry_frame_show_submenu(self->selected);
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
|
|
|
|
{
|
|
|
|
ObMenuFrame *f;
|
|
|
|
|
2003-08-28 07:49:57 +00:00
|
|
|
if (!self->entry->data.submenu.submenu) return;
|
|
|
|
|
2003-08-28 02:10:23 +00:00
|
|
|
f = menu_frame_new(self->entry->data.submenu.submenu,
|
|
|
|
self->frame->client);
|
2007-03-25 16:34:26 +00:00
|
|
|
/* pass our direction on to our child */
|
|
|
|
f->direction_right = self->frame->direction_right;
|
|
|
|
|
|
|
|
menu_frame_show_submenu(f, self->frame, self);
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-11 04:44:15 +00:00
|
|
|
void menu_entry_frame_execute(ObMenuEntryFrame *self, guint state, Time time)
|
2003-08-28 02:10:23 +00:00
|
|
|
{
|
2003-08-28 18:34:06 +00:00
|
|
|
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
self->entry->data.normal.enabled)
|
|
|
|
{
|
2003-08-28 17:15:10 +00:00
|
|
|
/* grab all this shizzle, cuz when the menu gets hidden, 'self'
|
|
|
|
gets freed */
|
|
|
|
ObMenuEntry *entry = self->entry;
|
|
|
|
ObMenuExecuteFunc func = self->frame->menu->execute_func;
|
|
|
|
gpointer data = self->frame->menu->data;
|
|
|
|
GSList *acts = self->entry->data.normal.actions;
|
2003-08-28 17:22:10 +00:00
|
|
|
ObClient *client = self->frame->client;
|
2003-08-28 17:15:10 +00:00
|
|
|
|
2003-08-28 05:44:13 +00:00
|
|
|
/* release grabs before executing the shit */
|
2003-09-07 19:03:20 +00:00
|
|
|
if (!(state & ControlMask))
|
2003-08-31 18:58:10 +00:00
|
|
|
menu_frame_hide_all();
|
2003-08-28 05:44:13 +00:00
|
|
|
|
2003-08-28 17:15:10 +00:00
|
|
|
if (func)
|
2007-03-11 04:44:15 +00:00
|
|
|
func(entry, state, data, time);
|
2003-09-19 17:41:05 +00:00
|
|
|
else
|
2007-03-11 04:44:15 +00:00
|
|
|
action_run(acts, client, state, time);
|
2003-08-28 02:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-29 08:44:55 +00:00
|
|
|
|
|
|
|
void menu_frame_select_previous(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
GList *it = NULL, *start;
|
|
|
|
|
|
|
|
if (self->entries) {
|
|
|
|
start = it = g_list_find(self->entries, self->selected);
|
|
|
|
while (TRUE) {
|
|
|
|
ObMenuEntryFrame *e;
|
|
|
|
|
|
|
|
it = it ? g_list_previous(it) : g_list_last(self->entries);
|
|
|
|
if (it == start)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
e = it->data;
|
2003-08-29 08:51:05 +00:00
|
|
|
if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
|
|
|
|
break;
|
|
|
|
if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
e->entry->data.normal.enabled)
|
2003-08-29 08:44:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-25 01:33:20 +00:00
|
|
|
menu_frame_select(self, it ? it->data : NULL, TRUE);
|
2003-08-29 08:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void menu_frame_select_next(ObMenuFrame *self)
|
|
|
|
{
|
|
|
|
GList *it = NULL, *start;
|
|
|
|
|
|
|
|
if (self->entries) {
|
|
|
|
start = it = g_list_find(self->entries, self->selected);
|
|
|
|
while (TRUE) {
|
|
|
|
ObMenuEntryFrame *e;
|
|
|
|
|
|
|
|
it = it ? g_list_next(it) : self->entries;
|
|
|
|
if (it == start)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
e = it->data;
|
2003-08-29 08:51:05 +00:00
|
|
|
if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
|
|
|
|
break;
|
|
|
|
if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
|
|
|
|
e->entry->data.normal.enabled)
|
2003-08-29 08:44:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-25 01:33:20 +00:00
|
|
|
menu_frame_select(self, it ? it->data : NULL, TRUE);
|
2003-08-29 08:44:55 +00:00
|
|
|
}
|