Merge branch 'master' into snap-range

This commit is contained in:
elviosak 2025-12-04 09:12:58 -03:00
commit cb6b2d9cda
38 changed files with 930 additions and 790 deletions

View file

@ -10,6 +10,17 @@ bool box_intersects(struct wlr_box *box_a, struct wlr_box *box_b);
void box_union(struct wlr_box *box_dest, struct wlr_box *box_a,
struct wlr_box *box_b);
/*
* Centers a content box (width & height) within a reference box,
* limiting it (if possible) to not extend outside a bounding box.
*
* The reference box and bounding box are often the same but could be
* different (e.g. when centering a view within its parent but limiting
* to usable output area).
*/
void box_center(int width, int height, const struct wlr_box *ref,
const struct wlr_box *bound, int *x, int *y);
/*
* Fits and centers a content box (width & height) within a bounding box.
* The content box is downscaled if necessary (preserving aspect ratio) but

View file

@ -47,7 +47,7 @@ enum lab_node_type {
LAB_NODE_FRAME,
LAB_NODE_ROOT,
LAB_NODE_MENUITEM,
LAB_NODE_OSD_ITEM,
LAB_NODE_CYCLE_OSD_ITEM,
LAB_NODE_LAYER_SURFACE,
LAB_NODE_UNMANAGED,
LAB_NODE_ALL,

View file

@ -183,8 +183,8 @@ struct rcxml {
bool unshade;
enum lab_view_criteria criteria;
struct wl_list fields; /* struct window_switcher_field.link */
enum window_switcher_style style;
enum osd_output_criteria output_criteria;
enum cycle_osd_style style;
enum cycle_osd_output_criteria output_criteria;
char *thumbnail_label_format;
} window_switcher;

View file

@ -107,15 +107,15 @@ enum lab_window_type {
LAB_WINDOW_TYPE_LEN
};
enum window_switcher_style {
WINDOW_SWITCHER_CLASSIC,
WINDOW_SWITCHER_THUMBNAIL,
enum cycle_osd_style {
CYCLE_OSD_STYLE_CLASSIC,
CYCLE_OSD_STYLE_THUMBNAIL,
};
enum osd_output_criteria {
OSD_OUTPUT_ALL,
OSD_OUTPUT_POINTER,
OSD_OUTPUT_KEYBOARD,
enum cycle_osd_output_criteria {
CYCLE_OSD_OUTPUT_ALL,
CYCLE_OSD_OUTPUT_CURSOR,
CYCLE_OSD_OUTPUT_FOCUSED,
};
#endif /* LABWC_CONFIG_TYPES_H */

View file

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_OSD_H
#define LABWC_OSD_H
#ifndef LABWC_CYCLE_H
#define LABWC_CYCLE_H
#include <stdbool.h>
#include <wayland-server-core.h>
@ -14,7 +14,7 @@ enum lab_cycle_dir {
};
/* TODO: add field with keyboard layout? */
enum window_switcher_field_content {
enum cycle_osd_field_content {
LAB_FIELD_NONE = 0,
LAB_FIELD_TYPE,
LAB_FIELD_TYPE_SHORT,
@ -35,8 +35,8 @@ enum window_switcher_field_content {
LAB_FIELD_COUNT
};
struct window_switcher_field {
enum window_switcher_field_content content;
struct cycle_osd_field {
enum cycle_osd_field_content content;
int width;
char *format;
struct wl_list link; /* struct rcxml.window_switcher.fields */
@ -48,54 +48,54 @@ struct server;
struct wlr_scene_node;
/* Begin window switcher */
void osd_begin(struct server *server, enum lab_cycle_dir direction);
void cycle_begin(struct server *server, enum lab_cycle_dir direction);
/* Cycle the selected view in the window switcher */
void osd_cycle(struct server *server, enum lab_cycle_dir direction);
void cycle_step(struct server *server, enum lab_cycle_dir direction);
/* Closes the OSD */
void osd_finish(struct server *server, bool switch_focus);
void cycle_finish(struct server *server, bool switch_focus);
/* Notify OSD about a destroying view */
void osd_on_view_destroy(struct view *view);
/* Re-initialize the window switcher */
void cycle_reinitialize(struct server *server);
/* Focus the clicked window and close OSD */
void osd_on_cursor_release(struct server *server, struct wlr_scene_node *node);
void cycle_on_cursor_release(struct server *server, struct wlr_scene_node *node);
/* Used by osd.c internally to render window switcher fields */
void osd_field_get_content(struct window_switcher_field *field,
void cycle_osd_field_get_content(struct cycle_osd_field *field,
struct buf *buf, struct view *view);
/* Sets view info to buf according to format */
void osd_field_set_custom(struct buf *buf, struct view *view,
void cycle_osd_field_set_custom(struct buf *buf, struct view *view,
const char *format);
/* Used by rcxml.c when parsing the config */
void osd_field_arg_from_xml_node(struct window_switcher_field *field,
void cycle_osd_field_arg_from_xml_node(struct cycle_osd_field *field,
const char *nodename, const char *content);
bool osd_field_is_valid(struct window_switcher_field *field);
void osd_field_free(struct window_switcher_field *field);
bool cycle_osd_field_is_valid(struct cycle_osd_field *field);
void cycle_osd_field_free(struct cycle_osd_field *field);
/* Internal API */
struct osd_item {
struct cycle_osd_item {
struct view *view;
struct wlr_scene_tree *tree;
struct wl_list link;
};
struct osd_impl {
struct cycle_osd_impl {
/*
* Create a scene-tree of OSD for an output.
* This sets output->osd_scene.{items,tree}.
* This sets output->cycle_osd.{items,tree}.
*/
void (*create)(struct output *output, struct wl_array *views);
void (*create)(struct output *output);
/*
* Update output->osd_scene.tree to highlight
* server->osd_state.cycle_view.
* Update output->cycle_osd.tree to highlight
* server->cycle_state.selected_view.
*/
void (*update)(struct output *output);
};
extern struct osd_impl osd_classic_impl;
extern struct osd_impl osd_thumbnail_impl;
extern struct cycle_osd_impl cycle_osd_classic_impl;
extern struct cycle_osd_impl cycle_osd_thumbnail_impl;
#endif // LABWC_OSD_H
#endif // LABWC_CYCLE_H

View file

@ -38,6 +38,14 @@ struct cursor_context {
double sx, sy;
};
/* Used to persistently store cursor context (e.g. in seat->pressed) */
struct cursor_context_saved {
struct cursor_context ctx;
struct wl_listener view_destroy;
struct wl_listener node_destroy;
struct wl_listener surface_destroy;
};
/**
* get_cursor_context - find view, surface and scene_node at cursor
*
@ -65,6 +73,13 @@ void cursor_set(struct seat *seat, enum lab_cursors cursor);
void cursor_set_visible(struct seat *seat, bool visible);
/*
* Safely store a cursor context to saved_ctx. saved_ctx is cleared when either
* of its node, surface and view is destroyed.
*/
void cursor_context_save(struct cursor_context_saved *saved_ctx,
const struct cursor_context *ctx);
/**
* cursor_get_resize_edges - calculate resize edge based on cursor position
* @cursor - the current cursor (usually server->seat.cursor)

View file

@ -18,7 +18,7 @@ enum input_mode {
LAB_INPUT_STATE_MOVE,
LAB_INPUT_STATE_RESIZE,
LAB_INPUT_STATE_MENU,
LAB_INPUT_STATE_WINDOW_SWITCHER,
LAB_INPUT_STATE_CYCLE, /* a.k.a. window switching */
};
struct seat {
@ -65,8 +65,7 @@ struct seat {
struct input_method_relay *input_method_relay;
/**
* This is usually zeroed and is only set on button press while the
* mouse is over a view or surface, and zeroed on button release.
* Cursor context saved when a mouse button is pressed on a view/surface.
* It is used to send cursor motion events to a surface even though
* the cursor has left the surface in the meantime.
*
@ -76,10 +75,11 @@ struct seat {
* It is also used to:
* - determine the target view for action in "Drag" mousebind
* - validate view move/resize requests from CSD clients
*
* Both (view && !surface) and (surface && !view) are possible.
*/
struct cursor_context pressed;
struct cursor_context_saved pressed;
/* Cursor context of the last cursor motion */
struct cursor_context_saved last_cursor_ctx;
struct lab_set bound_buttons;
@ -139,7 +139,6 @@ struct seat {
struct wl_list tablet_pads;
struct wl_listener constraint_commit;
struct wl_listener pressed_surface_destroy;
struct wlr_virtual_pointer_manager_v1 *virtual_pointer;
struct wl_listener new_virtual_pointer;
@ -302,15 +301,15 @@ struct server {
struct wlr_security_context_manager_v1 *security_context_manager_v1;
/* Set when in cycle (alt-tab) mode */
struct osd_state {
struct view *cycle_view;
struct cycle_state {
struct view *selected_view;
struct wl_list views;
bool preview_was_shaded;
bool preview_was_enabled;
struct wlr_scene_node *preview_node;
struct wlr_scene_tree *preview_parent;
struct wlr_scene_node *preview_anchor;
struct wlr_scene_node *preview_dummy;
struct lab_scene_rect *preview_outline;
} osd_state;
} cycle;
struct theme *theme;
@ -392,8 +391,6 @@ void seat_pointer_end_grab(struct seat *seat, struct wlr_surface *surface);
void seat_focus_lock_surface(struct seat *seat, struct wlr_surface *surface);
void seat_set_focus_layer(struct seat *seat, struct wlr_layer_surface_v1 *layer);
void seat_set_pressed(struct seat *seat, struct cursor_context *ctx);
void seat_reset_pressed(struct seat *seat);
void seat_output_layout_changed(struct seat *seat);
/*

View file

@ -53,10 +53,10 @@ struct menuitem *node_menuitem_from_node(
struct wlr_scene_node *wlr_scene_node);
/**
* node_osd_item_from_node - return osd item struct from node
* node_cycle_osd_item_from_node - return cycle OSD item struct from node
* @wlr_scene_node: wlr_scene_node from which to return data
*/
struct osd_item *node_osd_item_from_node(
struct cycle_osd_item *node_cycle_osd_item_from_node(
struct wlr_scene_node *wlr_scene_node);
/**

View file

@ -15,14 +15,14 @@ struct output {
struct wlr_scene_output *scene_output;
struct wlr_scene_tree *layer_tree[LAB_NR_LAYERS];
struct wlr_scene_tree *layer_popup_tree;
struct wlr_scene_tree *osd_tree;
struct wlr_scene_tree *cycle_osd_tree;
struct wlr_scene_tree *session_lock_tree;
struct wlr_scene_buffer *workspace_osd;
struct osd_scene {
struct wl_list items; /* struct osd_item */
struct cycle_osd_scene {
struct wl_list items; /* struct cycle_osd_item */
struct wlr_scene_tree *tree;
} osd_scene;
} cycle_osd;
/* In output-relative scene coordinates */
struct wlr_box usable_area;

View file

@ -134,6 +134,9 @@ struct view {
const struct view_impl *impl;
struct wl_list link;
/* This is cleared when the view is not in the cycle list */
struct wl_list cycle_link;
/*
* The primary output that the view is displayed on. Specifically:
*
@ -293,6 +296,9 @@ struct xdg_toplevel_view {
struct view base;
struct wlr_xdg_surface *xdg_surface;
/* Optional black background fill behind fullscreen view */
struct wlr_scene_rect *fullscreen_bg;
/* Events unique to xdg-toplevel views */
struct wl_listener set_app_id;
struct wl_listener request_show_window_menu;
@ -384,15 +390,6 @@ struct view *view_next(struct wl_list *head, struct view *view,
struct view *view_prev(struct wl_list *head, struct view *view,
enum lab_view_criteria criteria);
/*
* Same as `view_next()` except that they iterate one whole cycle rather than
* stopping at the list-head
*/
struct view *view_next_no_head_stop(struct wl_list *head, struct view *from,
enum lab_view_criteria criteria);
struct view *view_prev_no_head_stop(struct wl_list *head, struct view *from,
enum lab_view_criteria criteria);
/**
* view_array_append() - Append views that match criteria to array
* @server: server context

View file

@ -77,5 +77,7 @@ void xwayland_update_workarea(struct server *server);
void xwayland_reset_cursor(struct server *server);
void xwayland_flush(struct server *server);
#endif /* HAVE_XWAYLAND */
#endif /* LABWC_XWAYLAND_H */