mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
refactor ssd_titlebar_create
This commit is contained in:
parent
39ff873d5b
commit
a28a3737b9
1 changed files with 64 additions and 105 deletions
|
|
@ -21,6 +21,64 @@
|
||||||
static void set_squared_corners(struct ssd *ssd, bool enable);
|
static void set_squared_corners(struct ssd *ssd, bool enable);
|
||||||
static void set_maximize_alt_icon(struct ssd *ssd, bool enable);
|
static void set_maximize_alt_icon(struct ssd *ssd, bool enable);
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_button(struct ssd *ssd, struct ssd_sub_tree *subtree, enum ssd_part_type type, int x)
|
||||||
|
{
|
||||||
|
struct view *view = ssd->view;
|
||||||
|
struct theme *theme = view->server->theme;
|
||||||
|
struct wlr_scene_tree *parent = subtree->tree;
|
||||||
|
bool active = subtree == &ssd->titlebar.active;
|
||||||
|
|
||||||
|
struct ssd_part *btn_max_root;
|
||||||
|
struct ssd_button *btn_max;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case LAB_SSD_BUTTON_WINDOW_MENU:
|
||||||
|
add_scene_button(&subtree->parts, type, parent,
|
||||||
|
active ? &theme->button_menu_active_unpressed->base
|
||||||
|
: &theme->button_menu_inactive_unpressed->base,
|
||||||
|
active ? &theme->button_menu_active_hover->base
|
||||||
|
: &theme->button_menu_inactive_hover->base,
|
||||||
|
x, view);
|
||||||
|
break;
|
||||||
|
case LAB_SSD_BUTTON_ICONIFY:
|
||||||
|
add_scene_button(&subtree->parts, type, parent,
|
||||||
|
active ? &theme->button_iconify_active_unpressed->base
|
||||||
|
: &theme->button_iconify_inactive_unpressed->base,
|
||||||
|
active ? &theme->button_iconify_active_hover->base
|
||||||
|
: &theme->button_iconify_inactive_hover->base,
|
||||||
|
x, view);
|
||||||
|
break;
|
||||||
|
case LAB_SSD_BUTTON_MAXIMIZE:
|
||||||
|
/* Maximize button has an alternate state when maximized */
|
||||||
|
btn_max_root = add_scene_button(&subtree->parts, type, parent,
|
||||||
|
active ? &theme->button_maximize_active_unpressed->base
|
||||||
|
: &theme->button_maximize_inactive_unpressed->base,
|
||||||
|
active ? &theme->button_maximize_active_hover->base
|
||||||
|
: &theme->button_maximize_inactive_hover->base,
|
||||||
|
x, view);
|
||||||
|
btn_max = node_ssd_button_from_node(btn_max_root->node);
|
||||||
|
add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
|
||||||
|
active ? &theme->button_restore_active_unpressed->base
|
||||||
|
: &theme->button_restore_inactive_unpressed->base,
|
||||||
|
active ? &theme->button_restore_active_hover->base
|
||||||
|
: &theme->button_restore_inactive_hover->base);
|
||||||
|
break;
|
||||||
|
case LAB_SSD_BUTTON_CLOSE:
|
||||||
|
add_scene_button(&subtree->parts, type, parent,
|
||||||
|
active ? &theme->button_close_active_unpressed->base
|
||||||
|
: &theme->button_close_inactive_unpressed->base,
|
||||||
|
active ? &theme->button_close_active_hover->base
|
||||||
|
: &theme->button_close_inactive_hover->base,
|
||||||
|
x, view);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false && "invalid titlebar part");
|
||||||
|
wlr_log(WLR_ERROR, "invalid titlebar type");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ssd_titlebar_create(struct ssd *ssd)
|
ssd_titlebar_create(struct ssd *ssd)
|
||||||
{
|
{
|
||||||
|
|
@ -33,18 +91,6 @@ ssd_titlebar_create(struct ssd *ssd)
|
||||||
struct wlr_buffer *corner_top_left;
|
struct wlr_buffer *corner_top_left;
|
||||||
struct wlr_buffer *corner_top_right;
|
struct wlr_buffer *corner_top_right;
|
||||||
|
|
||||||
struct wlr_buffer *menu_button_unpressed;
|
|
||||||
struct wlr_buffer *iconify_button_unpressed;
|
|
||||||
struct wlr_buffer *maximize_button_unpressed;
|
|
||||||
struct wlr_buffer *restore_button_unpressed;
|
|
||||||
struct wlr_buffer *close_button_unpressed;
|
|
||||||
|
|
||||||
struct wlr_buffer *menu_button_hover;
|
|
||||||
struct wlr_buffer *iconify_button_hover;
|
|
||||||
struct wlr_buffer *maximize_button_hover;
|
|
||||||
struct wlr_buffer *restore_button_hover;
|
|
||||||
struct wlr_buffer *close_button_hover;
|
|
||||||
|
|
||||||
ssd->titlebar.tree = wlr_scene_tree_create(ssd->tree);
|
ssd->titlebar.tree = wlr_scene_tree_create(ssd->tree);
|
||||||
|
|
||||||
struct ssd_sub_tree *subtree;
|
struct ssd_sub_tree *subtree;
|
||||||
|
|
@ -56,33 +102,10 @@ ssd_titlebar_create(struct ssd *ssd)
|
||||||
color = theme->window_active_title_bg_color;
|
color = theme->window_active_title_bg_color;
|
||||||
corner_top_left = &theme->corner_top_left_active_normal->base;
|
corner_top_left = &theme->corner_top_left_active_normal->base;
|
||||||
corner_top_right = &theme->corner_top_right_active_normal->base;
|
corner_top_right = &theme->corner_top_right_active_normal->base;
|
||||||
menu_button_unpressed = &theme->button_menu_active_unpressed->base;
|
|
||||||
iconify_button_unpressed = &theme->button_iconify_active_unpressed->base;
|
|
||||||
close_button_unpressed = &theme->button_close_active_unpressed->base;
|
|
||||||
maximize_button_unpressed = &theme->button_maximize_active_unpressed->base;
|
|
||||||
restore_button_unpressed = &theme->button_restore_active_unpressed->base;
|
|
||||||
|
|
||||||
menu_button_hover = &theme->button_menu_active_hover->base;
|
|
||||||
iconify_button_hover = &theme->button_iconify_active_hover->base;
|
|
||||||
close_button_hover = &theme->button_close_active_hover->base;
|
|
||||||
maximize_button_hover = &theme->button_maximize_active_hover->base;
|
|
||||||
restore_button_hover = &theme->button_restore_active_hover->base;
|
|
||||||
} else {
|
} else {
|
||||||
color = theme->window_inactive_title_bg_color;
|
color = theme->window_inactive_title_bg_color;
|
||||||
corner_top_left = &theme->corner_top_left_inactive_normal->base;
|
corner_top_left = &theme->corner_top_left_inactive_normal->base;
|
||||||
corner_top_right = &theme->corner_top_right_inactive_normal->base;
|
corner_top_right = &theme->corner_top_right_inactive_normal->base;
|
||||||
menu_button_unpressed = &theme->button_menu_inactive_unpressed->base;
|
|
||||||
iconify_button_unpressed = &theme->button_iconify_inactive_unpressed->base;
|
|
||||||
maximize_button_unpressed =
|
|
||||||
&theme->button_maximize_inactive_unpressed->base;
|
|
||||||
restore_button_unpressed = &theme->button_restore_inactive_unpressed->base;
|
|
||||||
close_button_unpressed = &theme->button_close_inactive_unpressed->base;
|
|
||||||
|
|
||||||
menu_button_hover = &theme->button_menu_inactive_hover->base;
|
|
||||||
iconify_button_hover = &theme->button_iconify_inactive_hover->base;
|
|
||||||
close_button_hover = &theme->button_close_inactive_hover->base;
|
|
||||||
maximize_button_hover = &theme->button_maximize_inactive_hover->base;
|
|
||||||
restore_button_hover = &theme->button_restore_inactive_hover->base;
|
|
||||||
|
|
||||||
wlr_scene_node_set_enabled(&parent->node, false);
|
wlr_scene_node_set_enabled(&parent->node, false);
|
||||||
}
|
}
|
||||||
|
|
@ -99,81 +122,17 @@ ssd_titlebar_create(struct ssd *ssd)
|
||||||
-rc.theme->border_width);
|
-rc.theme->border_width);
|
||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
int x = 0;
|
|
||||||
struct ssd_part *btn_max_root;
|
|
||||||
struct ssd_button *btn_max;
|
|
||||||
struct title_button *b;
|
struct title_button *b;
|
||||||
|
int x = 0;
|
||||||
wl_list_for_each(b, &rc.title_buttons_left, link) {
|
wl_list_for_each(b, &rc.title_buttons_left, link) {
|
||||||
switch (b->type) {
|
add_button(ssd, subtree, b->type, x);
|
||||||
case LAB_SSD_BUTTON_WINDOW_MENU:
|
x += theme->window_button_width;
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
|
|
||||||
parent, menu_button_unpressed, menu_button_hover, x,
|
|
||||||
view);
|
|
||||||
x += theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_ICONIFY:
|
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
|
|
||||||
iconify_button_unpressed, iconify_button_hover, x,
|
|
||||||
view);
|
|
||||||
x += theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_MAXIMIZE:
|
|
||||||
/* Maximize button has an alternate state when maximized */
|
|
||||||
btn_max_root = add_scene_button(
|
|
||||||
&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
|
|
||||||
maximize_button_unpressed, maximize_button_hover, x, view);
|
|
||||||
btn_max = node_ssd_button_from_node(btn_max_root->node);
|
|
||||||
add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
|
|
||||||
restore_button_unpressed, restore_button_hover);
|
|
||||||
x += theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_CLOSE:
|
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_CLOSE, parent,
|
|
||||||
close_button_unpressed, close_button_hover, x, view);
|
|
||||||
x += theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
assert(false && "invalid titlebar part");
|
|
||||||
wlr_log(WLR_ERROR, "invalid titlebar type");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x = width - theme->window_button_width;
|
x = width;
|
||||||
wl_list_for_each_reverse(b, &rc.title_buttons_right, link) {
|
wl_list_for_each_reverse(b, &rc.title_buttons_right, link) {
|
||||||
switch (b->type) {
|
x -= theme->window_button_width;
|
||||||
case LAB_SSD_BUTTON_WINDOW_MENU:
|
add_button(ssd, subtree, b->type, x);
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_WINDOW_MENU,
|
|
||||||
parent, menu_button_unpressed, menu_button_hover, x,
|
|
||||||
view);
|
|
||||||
x -= theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_ICONIFY:
|
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_ICONIFY, parent,
|
|
||||||
iconify_button_unpressed, iconify_button_hover, x,
|
|
||||||
view);
|
|
||||||
x -= theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_MAXIMIZE:
|
|
||||||
/* Maximize button has an alternate state when maximized */
|
|
||||||
btn_max_root = add_scene_button(
|
|
||||||
&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE, parent,
|
|
||||||
maximize_button_unpressed, maximize_button_hover, x, view);
|
|
||||||
btn_max = node_ssd_button_from_node(btn_max_root->node);
|
|
||||||
add_toggled_icon(btn_max, &subtree->parts, LAB_SSD_BUTTON_MAXIMIZE,
|
|
||||||
restore_button_unpressed, restore_button_hover);
|
|
||||||
x -= theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
case LAB_SSD_BUTTON_CLOSE:
|
|
||||||
add_scene_button(&subtree->parts, LAB_SSD_BUTTON_CLOSE, parent,
|
|
||||||
close_button_unpressed, close_button_hover, x, view);
|
|
||||||
x -= theme->window_button_width;
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
assert(false && "invalid titlebar part");
|
|
||||||
wlr_log(WLR_ERROR, "invalid titlebar type");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} FOR_EACH_END
|
} FOR_EACH_END
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue