mirror of
https://github.com/labwc/labwc.git
synced 2025-11-07 13:30:06 -05:00
ssd: add optional shade button
This commit is contained in:
parent
9f2eae672c
commit
186a07be9b
11 changed files with 138 additions and 34 deletions
|
|
@ -19,7 +19,7 @@
|
|||
&(ssd)->titlebar.inactive)
|
||||
|
||||
static void set_squared_corners(struct ssd *ssd, bool enable);
|
||||
static void set_maximize_alt_icon(struct ssd *ssd, bool enable);
|
||||
static void set_alt_button_icon(struct ssd *ssd, enum ssd_part_type type, bool enable);
|
||||
|
||||
static void
|
||||
add_button(struct ssd *ssd, struct ssd_sub_tree *subtree, enum ssd_part_type type, int x)
|
||||
|
|
@ -29,8 +29,8 @@ add_button(struct ssd *ssd, struct ssd_sub_tree *subtree, enum ssd_part_type typ
|
|||
struct wlr_scene_tree *parent = subtree->tree;
|
||||
bool active = subtree == &ssd->titlebar.active;
|
||||
|
||||
struct ssd_part *btn_max_root;
|
||||
struct ssd_button *btn_max;
|
||||
struct ssd_part *btn_root;
|
||||
struct ssd_button *btn;
|
||||
|
||||
switch (type) {
|
||||
case LAB_SSD_BUTTON_WINDOW_MENU:
|
||||
|
|
@ -51,19 +51,34 @@ add_button(struct ssd *ssd, struct ssd_sub_tree *subtree, enum ssd_part_type typ
|
|||
break;
|
||||
case LAB_SSD_BUTTON_MAXIMIZE:
|
||||
/* Maximize button has an alternate state when maximized */
|
||||
btn_max_root = add_scene_button(&subtree->parts, type, parent,
|
||||
btn_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,
|
||||
btn = node_ssd_button_from_node(btn_root->node);
|
||||
add_toggled_icon(btn, &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_SHADE:
|
||||
/* Shade button has an alternate state when shaded */
|
||||
btn_root = add_scene_button(&subtree->parts, type, parent,
|
||||
active ? &theme->button_shade_active_unpressed->base
|
||||
: &theme->button_shade_inactive_unpressed->base,
|
||||
active ? &theme->button_shade_active_hover->base
|
||||
: &theme->button_shade_inactive_hover->base,
|
||||
x, view);
|
||||
btn = node_ssd_button_from_node(btn_root->node);
|
||||
add_toggled_icon(btn, &subtree->parts, LAB_SSD_BUTTON_SHADE,
|
||||
active ? &theme->button_unshade_active_unpressed->base
|
||||
: &theme->button_unshade_inactive_unpressed->base,
|
||||
active ? &theme->button_unshade_active_hover->base
|
||||
: &theme->button_unshade_inactive_hover->base);
|
||||
break;
|
||||
case LAB_SSD_BUTTON_CLOSE:
|
||||
add_scene_button(&subtree->parts, type, parent,
|
||||
active ? &theme->button_close_active_unpressed->base
|
||||
|
|
@ -141,9 +156,14 @@ ssd_titlebar_create(struct ssd *ssd)
|
|||
bool maximized = view->maximized == VIEW_AXIS_BOTH;
|
||||
if (maximized) {
|
||||
set_squared_corners(ssd, true);
|
||||
set_maximize_alt_icon(ssd, true);
|
||||
set_alt_button_icon(ssd, LAB_SSD_BUTTON_MAXIMIZE, true);
|
||||
ssd->state.was_maximized = true;
|
||||
}
|
||||
|
||||
if (view->shaded) {
|
||||
set_alt_button_icon(ssd, LAB_SSD_BUTTON_SHADE, true);
|
||||
}
|
||||
|
||||
if (view_is_tiled_and_notify_tiled(view) && !maximized) {
|
||||
set_squared_corners(ssd, true);
|
||||
ssd->state.was_tiled_not_maximized = true;
|
||||
|
|
@ -176,14 +196,14 @@ set_squared_corners(struct ssd *ssd, bool enable)
|
|||
}
|
||||
|
||||
static void
|
||||
set_maximize_alt_icon(struct ssd *ssd, bool enable)
|
||||
set_alt_button_icon(struct ssd *ssd, enum ssd_part_type type, bool enable)
|
||||
{
|
||||
struct ssd_part *part;
|
||||
struct ssd_button *button;
|
||||
struct ssd_sub_tree *subtree;
|
||||
|
||||
FOR_EACH_STATE(ssd, subtree) {
|
||||
part = ssd_get_part(&subtree->parts, LAB_SSD_BUTTON_MAXIMIZE);
|
||||
part = ssd_get_part(&subtree->parts, type);
|
||||
if (!part) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -214,12 +234,17 @@ ssd_titlebar_update(struct ssd *ssd)
|
|||
&& !maximized;
|
||||
|
||||
if (ssd->state.was_maximized != maximized
|
||||
|| ssd->state.was_shaded != view->shaded
|
||||
|| ssd->state.was_tiled_not_maximized != tiled_not_maximized) {
|
||||
set_squared_corners(ssd, maximized || tiled_not_maximized);
|
||||
if (ssd->state.was_maximized != maximized) {
|
||||
set_maximize_alt_icon(ssd, maximized);
|
||||
set_alt_button_icon(ssd, LAB_SSD_BUTTON_MAXIMIZE, maximized);
|
||||
}
|
||||
if (ssd->state.was_shaded != view->shaded) {
|
||||
set_alt_button_icon(ssd, LAB_SSD_BUTTON_SHADE, view->shaded);
|
||||
}
|
||||
ssd->state.was_maximized = maximized;
|
||||
ssd->state.was_shaded = view->shaded;
|
||||
ssd->state.was_tiled_not_maximized = tiled_not_maximized;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,15 +74,6 @@ ssd_max_extents(struct view *view)
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ssd_is_button(enum ssd_part_type type)
|
||||
{
|
||||
return type == LAB_SSD_BUTTON_CLOSE
|
||||
|| type == LAB_SSD_BUTTON_MAXIMIZE
|
||||
|| type == LAB_SSD_BUTTON_ICONIFY
|
||||
|| type == LAB_SSD_BUTTON_WINDOW_MENU;
|
||||
}
|
||||
|
||||
enum ssd_part_type
|
||||
ssd_get_part_type(const struct ssd *ssd, struct wlr_scene_node *node)
|
||||
{
|
||||
|
|
@ -257,16 +248,17 @@ ssd_update_geometry(struct ssd *ssd)
|
|||
ssd->state.geometry = current;
|
||||
}
|
||||
bool maximized = ssd->view->maximized == VIEW_AXIS_BOTH;
|
||||
if (ssd->state.was_maximized != maximized) {
|
||||
if (ssd->state.was_maximized != maximized
|
||||
|| ssd->state.was_shaded != ssd->view->shaded) {
|
||||
ssd_titlebar_update(ssd);
|
||||
ssd_border_update(ssd);
|
||||
ssd_shadow_update(ssd);
|
||||
/*
|
||||
* Not strictly necessary as ssd_titlebar_update()
|
||||
* already sets state.was_maximized but to future
|
||||
* proof this a bit we also set it here again.
|
||||
* already sets these values, but set here to be safe.
|
||||
*/
|
||||
ssd->state.was_maximized = maximized;
|
||||
ssd->state.was_shaded = ssd->view->shaded;
|
||||
}
|
||||
bool tiled_and_not_maximized = view_is_tiled(ssd->view) && !maximized;
|
||||
if (ssd->state.was_tiled_not_maximized != tiled_and_not_maximized) {
|
||||
|
|
@ -403,6 +395,7 @@ ssd_enable_shade(struct ssd *ssd, bool enable)
|
|||
if (!ssd) {
|
||||
return;
|
||||
}
|
||||
ssd_titlebar_update(ssd);
|
||||
ssd_border_update(ssd);
|
||||
wlr_scene_node_set_enabled(&ssd->extents.tree->node, !enable);
|
||||
ssd_shadow_update(ssd);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue