include: add config/types.h

This commit is contained in:
John Lindgren 2025-08-17 16:01:50 -04:00 committed by Hiroaki Yamamoto
parent 6dea8c0dcc
commit 9d49d19cd2
54 changed files with 414 additions and 368 deletions

View file

@ -3,9 +3,9 @@
#define LABWC_DIRECTION_H
#include <wlr/types/wlr_output_layout.h>
#include "view.h"
#include "config/types.h"
bool direction_from_view_edge(enum view_edge edge, enum wlr_direction *direction);
bool direction_from_edge(enum lab_edge edge, enum wlr_direction *direction);
enum wlr_direction direction_get_opposite(enum wlr_direction direction);
#endif /* LABWC_DIRECTION_H */

View file

@ -1,17 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_PARSE_BOOL_H
#define LABWC_PARSE_BOOL_H
#include <stdbool.h>
#include "common/three-state.h"
#include "config/types.h"
/**
* parse_three_state() - Parse boolean value of string as a three-state enum.
* parse_tristate() - Parse boolean value of string as a three-state enum.
* @string: String to interpret. This check is case-insensitive.
*
* Return: LAB_STATE_DISABLED for false; LAB_STATE_ENABLED for true;
* LAB_STATE_UNSPECIFIED for non-boolean
*/
enum three_state parse_three_state(const char *str);
enum lab_tristate parse_tristate(const char *str);
/**
* parse_bool() - Parse boolean value of string.

View file

@ -1,11 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_THREE_STATE_H
#define LABWC_THREE_STATE_H
enum three_state {
LAB_STATE_UNSPECIFIED = 0,
LAB_STATE_ENABLED,
LAB_STATE_DISABLED
};
#endif /* LABWC_THREE_STATE_H */

View file

@ -3,29 +3,17 @@
#define LABWC_RCXML_H
#include <stdbool.h>
#include <stdio.h>
#include <wayland-server-core.h>
#include <wlr/util/box.h>
#include <libxml/tree.h>
#include "common/border.h"
#include "common/buf.h"
#include "common/font.h"
#include "common/three-state.h"
#include "config/touch.h"
#include "config/tablet.h"
#include "config/tablet-tool.h"
#include "config/libinput.h"
#include "resize-indicator.h"
#include "config/types.h"
#include "ssd.h"
#include "theme.h"
enum view_placement_policy {
LAB_PLACE_INVALID = 0,
LAB_PLACE_CENTER,
LAB_PLACE_CURSOR,
LAB_PLACE_AUTOMATIC,
LAB_PLACE_CASCADE,
};
#define BUTTON_MAP_MAX 16
enum adaptive_sync_mode {
LAB_ADAPTIVE_SYNC_DISABLED,
@ -33,6 +21,12 @@ enum adaptive_sync_mode {
LAB_ADAPTIVE_SYNC_FULLSCREEN,
};
enum resize_indicator_mode {
LAB_RESIZE_INDICATOR_NEVER = 0,
LAB_RESIZE_INDICATOR_ALWAYS,
LAB_RESIZE_INDICATOR_NON_PIXEL
};
enum tearing_mode {
LAB_TEARING_DISABLED = 0,
LAB_TEARING_ENABLED,
@ -48,6 +42,11 @@ enum tiling_events_mode {
(LAB_TILING_EVENTS_REGION | LAB_TILING_EVENTS_EDGE),
};
struct button_map_entry {
uint32_t from;
uint32_t to;
};
struct title_button {
enum ssd_part_type type;
struct wl_list link;
@ -72,7 +71,7 @@ struct rcxml {
enum tearing_mode allow_tearing;
bool auto_enable_outputs;
bool reuse_output_mode;
enum view_placement_policy placement_policy;
enum lab_placement_policy placement_policy;
bool xwayland_persistence;
bool primary_selection;
int placement_cascade_offset_x;
@ -110,7 +109,7 @@ struct rcxml {
/* keyboard */
int repeat_rate;
int repeat_delay;
enum three_state kb_numlock_enable;
enum lab_tristate kb_numlock_enable;
bool kb_layout_per_window;
struct wl_list keybinds; /* struct keybind.link */
@ -126,12 +125,12 @@ struct rcxml {
bool force_mouse_emulation;
char *output_name;
struct wlr_fbox box;
enum rotation rotation;
enum lab_rotation rotation;
uint16_t button_map_count;
struct button_map_entry button_map[BUTTON_MAP_MAX];
} tablet;
struct tablet_tool_config {
enum motion motion;
enum lab_motion motion;
double relative_motion_sensitivity;
} tablet_tool;

View file

@ -2,13 +2,8 @@
#ifndef LABWC_TABLET_TOOL_CONFIG_H
#define LABWC_TABLET_TOOL_CONFIG_H
#include <stdint.h>
#include "config/types.h"
enum motion {
LAB_TABLET_MOTION_ABSOLUTE = 0,
LAB_TABLET_MOTION_RELATIVE,
};
enum motion tablet_parse_motion(const char *name);
enum lab_motion tablet_parse_motion(const char *name);
#endif /* LABWC_TABLET_TOOL_CONFIG_H */

View file

@ -3,22 +3,10 @@
#define LABWC_TABLET_CONFIG_H
#include <stdint.h>
enum rotation {
LAB_ROTATE_NONE = 0,
LAB_ROTATE_90,
LAB_ROTATE_180,
LAB_ROTATE_270,
};
#define BUTTON_MAP_MAX 16
struct button_map_entry {
uint32_t from;
uint32_t to;
};
#include "config/types.h"
double tablet_get_dbl_if_positive(const char *content, const char *name);
enum rotation tablet_parse_rotation(int value);
enum lab_rotation tablet_parse_rotation(int value);
uint32_t tablet_button_from_str(const char *button);
void tablet_button_mapping_add(uint32_t from, uint32_t to);
void tablet_load_default_button_mappings(void);

118
include/config/types.h Normal file
View file

@ -0,0 +1,118 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_CONFIG_TYPES_H
#define LABWC_CONFIG_TYPES_H
/*
* Shared (basic) types related to user configuration.
*
* Please try to keep dependencies on other headers minimal,
* since config/types.h gets included in many source files.
*
* For the full config struct, see config/rcxml.h.
*/
/**
* Edges to which a view can be snapped. "Any" is used as
* a catch-all for every valid edge in order to simplify certain
* types of conditionals, but it is only valid for a selection
* of options in rc.xml.
*/
enum lab_edge {
LAB_EDGE_INVALID = 0,
LAB_EDGE_LEFT = (1 << 0),
LAB_EDGE_RIGHT = (1 << 1),
LAB_EDGE_UP = (1 << 2),
LAB_EDGE_DOWN = (1 << 3),
LAB_EDGE_CENTER = (1 << 4),
LAB_EDGE_ANY = (1 << 5),
LAB_EDGE_UPLEFT = (LAB_EDGE_UP | LAB_EDGE_LEFT),
LAB_EDGE_UPRIGHT = (LAB_EDGE_UP | LAB_EDGE_RIGHT),
LAB_EDGE_DOWNLEFT = (LAB_EDGE_DOWN | LAB_EDGE_LEFT),
LAB_EDGE_DOWNRIGHT = (LAB_EDGE_DOWN | LAB_EDGE_RIGHT),
};
enum lab_motion {
LAB_MOTION_ABSOLUTE = 0,
LAB_MOTION_RELATIVE,
};
enum lab_placement_policy {
LAB_PLACE_INVALID = 0,
LAB_PLACE_CENTER,
LAB_PLACE_CURSOR,
LAB_PLACE_AUTOMATIC,
LAB_PLACE_CASCADE,
};
enum lab_rotation {
LAB_ROTATE_NONE = 0,
LAB_ROTATE_90,
LAB_ROTATE_180,
LAB_ROTATE_270,
};
enum lab_ssd_mode {
LAB_SSD_MODE_INVALID,
LAB_SSD_MODE_NONE,
LAB_SSD_MODE_BORDER,
LAB_SSD_MODE_FULL,
};
enum lab_tristate {
LAB_STATE_UNSPECIFIED = 0,
LAB_STATE_ENABLED,
LAB_STATE_DISABLED
};
/* All criteria is applied in AND logic */
enum lab_view_criteria {
/* No filter -> all focusable views */
LAB_VIEW_CRITERIA_NONE = 0,
/*
* Includes always-on-top views, e.g.
* what is visible on the current workspace
*/
LAB_VIEW_CRITERIA_CURRENT_WORKSPACE = 1 << 0,
/* Positive criteria */
LAB_VIEW_CRITERIA_FULLSCREEN = 1 << 1,
LAB_VIEW_CRITERIA_ALWAYS_ON_TOP = 1 << 2,
LAB_VIEW_CRITERIA_ROOT_TOPLEVEL = 1 << 3,
/* Negative criteria */
LAB_VIEW_CRITERIA_NO_ALWAYS_ON_TOP = 1 << 6,
LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER = 1 << 7,
LAB_VIEW_CRITERIA_NO_OMNIPRESENT = 1 << 8,
};
/*
* Window types are based on the NET_WM constants from X11. See:
* https://specifications.freedesktop.org/wm-spec/1.4/ar01s05.html#id-1.6.7
*
* The enum constants are intended to match wlr_xwayland_net_wm_window_type.
* Redefining the same constants here may seem redundant, but is necessary
* to make them available even in builds with xwayland support disabled.
*/
enum lab_window_type {
LAB_WINDOW_TYPE_DESKTOP = 0,
LAB_WINDOW_TYPE_DOCK,
LAB_WINDOW_TYPE_TOOLBAR,
LAB_WINDOW_TYPE_MENU,
LAB_WINDOW_TYPE_UTILITY,
LAB_WINDOW_TYPE_SPLASH,
LAB_WINDOW_TYPE_DIALOG,
LAB_WINDOW_TYPE_DROPDOWN_MENU,
LAB_WINDOW_TYPE_POPUP_MENU,
LAB_WINDOW_TYPE_TOOLTIP,
LAB_WINDOW_TYPE_NOTIFICATION,
LAB_WINDOW_TYPE_COMBO,
LAB_WINDOW_TYPE_DND,
LAB_WINDOW_TYPE_NORMAL,
LAB_WINDOW_TYPE_LEN
};
#endif /* LABWC_CONFIG_TYPES_H */

View file

@ -21,7 +21,7 @@ struct drawing_tablet_tool {
*/
bool force_mouse_emulation;
enum motion motion_mode;
enum lab_motion motion_mode;
double x, y, dx, dy;
double distance;
double pressure;

View file

@ -434,11 +434,11 @@ void interactive_cancel(struct view *view);
* Returns the edge to snap a window to.
* For example, if the output-relative cursor position (x,y) fulfills
* x <= (<snapping><cornerRange>) and y <= (<snapping><range>),
* then edge1=VIEW_EDGE_UP and edge2=VIEW_EDGE_LEFT.
* then edge1=LAB_EDGE_UP and edge2=LAB_EDGE_LEFT.
* The value of (edge1|edge2) can be passed to view_snap_to_edge().
*/
bool edge_from_cursor(struct seat *seat, struct output **dest_output,
enum view_edge *edge1, enum view_edge *edge2);
enum lab_edge *edge1, enum lab_edge *edge2);
void handle_tearing_new_object(struct wl_listener *listener, void *data);

View file

@ -4,7 +4,7 @@
#include <wlr/types/wlr_output.h>
enum view_edge;
enum lab_edge;
#define LAB_NR_LAYERS (4)
@ -60,7 +60,7 @@ struct output *output_nearest_to_cursor(struct server *server);
* reference instead.
*/
struct output *output_get_adjacent(struct output *output,
enum view_edge edge, bool wrap);
enum lab_edge edge, bool wrap);
bool output_is_usable(struct output *output);
void output_update_usable_area(struct output *output);

View file

@ -27,7 +27,7 @@ struct overlay {
struct region *region;
/* Snap-to-edge overlay */
enum view_edge edge;
enum lab_edge edge;
struct output *output;
} active;

View file

@ -5,12 +5,6 @@
struct server;
struct view;
enum resize_indicator_mode {
LAB_RESIZE_INDICATOR_NEVER = 0,
LAB_RESIZE_INDICATOR_ALWAYS,
LAB_RESIZE_INDICATOR_NON_PIXEL
};
void resize_indicator_reconfigure(struct server *server);
void resize_indicator_show(struct view *view);
void resize_indicator_update(struct view *view);

View file

@ -8,13 +8,13 @@
struct wlr_box;
void snap_move_to_edge(struct view *view,
enum view_edge direction, bool snap_to_windows, int *dx, int *dy);
enum lab_edge direction, bool snap_to_windows, int *dx, int *dy);
void snap_grow_to_next_edge(struct view *view,
enum view_edge direction, struct wlr_box *geo);
enum lab_edge direction, struct wlr_box *geo);
void snap_shrink_to_next_edge(struct view *view,
enum view_edge direction, struct wlr_box *geo);
enum lab_edge direction, struct wlr_box *geo);
void snap_invalidate_edge_cache(struct view *view);
void snap_update_cache_geometry(struct view *view);

View file

@ -5,6 +5,7 @@
#include <wlr/util/box.h>
#include "common/macros.h"
#include "ssd.h"
#include "theme.h"
#include "view.h"
#define FOR_EACH(tmp, ...) \

View file

@ -61,13 +61,6 @@ enum ssd_part_type {
LAB_SSD_END_MARKER
};
enum ssd_mode {
LAB_SSD_MODE_INVALID,
LAB_SSD_MODE_NONE,
LAB_SSD_MODE_BORDER,
LAB_SSD_MODE_FULL,
};
/* Forward declare arguments */
struct ssd;
struct ssd_button;
@ -110,7 +103,7 @@ enum ssd_part_type ssd_get_part_type(const struct ssd *ssd,
struct wlr_scene_node *node, struct wlr_cursor *cursor);
uint32_t ssd_resize_edges(enum ssd_part_type type);
bool ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate);
enum ssd_mode ssd_mode_parse(const char *mode);
enum lab_ssd_mode ssd_mode_parse(const char *mode);
/* TODO: clean up / update */
struct border ssd_thickness(struct view *view);

View file

@ -2,15 +2,13 @@
#ifndef LABWC_VIEW_H
#define LABWC_VIEW_H
#include "config/rcxml.h"
#include "config.h"
#include "ssd.h"
#include <stdbool.h>
#include <stdint.h>
#include <wayland-util.h>
#include <wlr/util/box.h>
#include <xkbcommon/xkbcommon.h>
#include "common/three-state.h"
#include "config.h"
#include "config/types.h"
#define LAB_MIN_VIEW_HEIGHT 60
@ -58,27 +56,6 @@ enum view_axis {
VIEW_AXIS_INVALID = (1 << 2),
};
/**
* Edges to which a view can be snapped to. "All" is used as
* a catchall for every valid edge in order to simplify certain
* types of conditionals, but it is only valid for a selection
* of options in rc.xml.
*/
enum view_edge {
VIEW_EDGE_INVALID = 0,
VIEW_EDGE_LEFT = (1 << 0),
VIEW_EDGE_RIGHT = (1 << 1),
VIEW_EDGE_UP = (1 << 2),
VIEW_EDGE_DOWN = (1 << 3),
VIEW_EDGE_CENTER = (1 << 4),
VIEW_EDGE_ANY = (1 << 5),
VIEW_EDGE_UPLEFT = (VIEW_EDGE_UP | VIEW_EDGE_LEFT),
VIEW_EDGE_UPRIGHT = (VIEW_EDGE_UP | VIEW_EDGE_RIGHT),
VIEW_EDGE_DOWNLEFT = (VIEW_EDGE_DOWN | VIEW_EDGE_LEFT),
VIEW_EDGE_DOWNRIGHT = (VIEW_EDGE_DOWN | VIEW_EDGE_RIGHT),
};
enum view_wants_focus {
/* View does not want focus */
VIEW_WANTS_FOCUS_NEVER = 0,
@ -99,33 +76,6 @@ enum view_wants_focus {
VIEW_WANTS_FOCUS_UNLIKELY,
};
/*
* Window types are based on the NET_WM constants from X11. See:
* https://specifications.freedesktop.org/wm-spec/1.4/ar01s05.html#id-1.6.7
*
* The enum constants are intended to match wlr_xwayland_net_wm_window_type.
* Redefining the same constants here may seem redundant, but is necessary
* to make them available even in builds with xwayland support disabled.
*/
enum window_type {
NET_WM_WINDOW_TYPE_DESKTOP = 0,
NET_WM_WINDOW_TYPE_DOCK,
NET_WM_WINDOW_TYPE_TOOLBAR,
NET_WM_WINDOW_TYPE_MENU,
NET_WM_WINDOW_TYPE_UTILITY,
NET_WM_WINDOW_TYPE_SPLASH,
NET_WM_WINDOW_TYPE_DIALOG,
NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
NET_WM_WINDOW_TYPE_POPUP_MENU,
NET_WM_WINDOW_TYPE_TOOLTIP,
NET_WM_WINDOW_TYPE_NOTIFICATION,
NET_WM_WINDOW_TYPE_COMBO,
NET_WM_WINDOW_TYPE_DND,
NET_WM_WINDOW_TYPE_NORMAL,
WINDOW_TYPE_LEN
};
struct view;
struct wlr_surface;
struct foreign_toplevel;
@ -175,7 +125,7 @@ struct view_impl {
bool (*has_strut_partial)(struct view *self);
/* returns true if view declared itself a window type */
bool (*contains_window_type)(struct view *view,
enum window_type window_type);
enum lab_window_type window_type);
/* returns the client pid that this view belongs to */
pid_t (*get_pid)(struct view *view);
};
@ -227,9 +177,9 @@ struct view {
enum view_axis maximized;
bool fullscreen;
bool tearing_hint;
enum three_state force_tearing;
enum lab_tristate force_tearing;
bool visible_on_all_workspaces;
enum view_edge tiled;
enum lab_edge tiled;
uint32_t edges_visible; /* enum wlr_edges bitset */
bool inhibits_keybinds; /* also inhibits mousebinds */
xkb_layout_index_t keyboard_layout;
@ -327,15 +277,15 @@ struct view_query {
int window_type;
char *sandbox_engine;
char *sandbox_app_id;
enum three_state shaded;
enum lab_tristate shaded;
enum view_axis maximized;
enum three_state iconified;
enum three_state focused;
enum three_state omnipresent;
enum view_edge tiled;
enum lab_tristate iconified;
enum lab_tristate focused;
enum lab_tristate omnipresent;
enum lab_edge tiled;
char *tiled_region;
char *desktop;
enum ssd_mode decoration;
enum lab_ssd_mode decoration;
char *monitor;
};
@ -349,28 +299,6 @@ struct xdg_toplevel_view {
struct wl_listener new_popup;
};
/* All criteria is applied in AND logic */
enum lab_view_criteria {
/* No filter -> all focusable views */
LAB_VIEW_CRITERIA_NONE = 0,
/*
* Includes always-on-top views, e.g.
* what is visible on the current workspace
*/
LAB_VIEW_CRITERIA_CURRENT_WORKSPACE = 1 << 0,
/* Positive criteria */
LAB_VIEW_CRITERIA_FULLSCREEN = 1 << 1,
LAB_VIEW_CRITERIA_ALWAYS_ON_TOP = 1 << 2,
LAB_VIEW_CRITERIA_ROOT_TOPLEVEL = 1 << 3,
/* Negative criteria */
LAB_VIEW_CRITERIA_NO_ALWAYS_ON_TOP = 1 << 6,
LAB_VIEW_CRITERIA_NO_SKIP_WINDOW_SWITCHER = 1 << 7,
LAB_VIEW_CRITERIA_NO_OMNIPRESENT = 1 << 8,
};
/**
* view_from_wlr_surface() - returns the view associated with a
* wlr_surface, or NULL if the surface has no associated view.
@ -492,20 +420,20 @@ void view_array_append(struct server *server, struct wl_array *views,
enum lab_view_criteria criteria);
enum view_wants_focus view_wants_focus(struct view *view);
bool view_contains_window_type(struct view *view, enum window_type window_type);
bool view_contains_window_type(struct view *view, enum lab_window_type window_type);
/**
* view_edge_invert() - select the opposite of a provided edge
*
* VIEW_EDGE_CENTER and VIEW_EDGE_INVALID both map to VIEW_EDGE_INVALID.
* LAB_EDGE_CENTER and LAB_EDGE_INVALID both map to LAB_EDGE_INVALID.
*
* @edge: edge to be inverted
*/
enum view_edge view_edge_invert(enum view_edge edge);
enum lab_edge view_edge_invert(enum lab_edge edge);
/* If view is NULL, the size of SSD is not considered */
struct wlr_box view_get_edge_snap_box(struct view *view, struct output *output,
enum view_edge edge);
enum lab_edge edge);
struct wlr_box view_get_region_snap_box(struct view *view, struct region *region);
/**
@ -529,7 +457,7 @@ bool view_is_focusable(struct view *view);
void view_offer_focus(struct view *view);
struct wlr_box view_get_edge_snap_box(struct view *view, struct output *output,
enum view_edge edge);
enum lab_edge edge);
void mappable_connect(struct mappable *mappable, struct wlr_surface *surface,
wl_notify_func_t notify_map, wl_notify_func_t notify_unmap);
@ -591,7 +519,7 @@ void view_center(struct view *view, const struct wlr_box *ref);
* @policy: placement policy to apply
*/
void view_place_by_policy(struct view *view, bool allow_cursor,
enum view_placement_policy policy);
enum lab_placement_policy policy);
void view_constrain_size_to_that_of_usable_area(struct view *view);
void view_restore_to(struct view *view, struct wlr_box geometry);
@ -614,16 +542,16 @@ bool view_is_tiled(struct view *view);
bool view_is_tiled_and_notify_tiled(struct view *view);
bool view_is_floating(struct view *view);
void view_move_to_workspace(struct view *view, struct workspace *workspace);
enum ssd_mode view_get_ssd_mode(struct view *view);
void view_set_ssd_mode(struct view *view, enum ssd_mode mode);
void view_set_decorations(struct view *view, enum ssd_mode mode, bool force_ssd);
enum lab_ssd_mode view_get_ssd_mode(struct view *view);
void view_set_ssd_mode(struct view *view, enum lab_ssd_mode mode);
void view_set_decorations(struct view *view, enum lab_ssd_mode mode, bool force_ssd);
void view_toggle_fullscreen(struct view *view);
void view_invalidate_last_layout_geometry(struct view *view);
void view_adjust_for_layout_change(struct view *view);
void view_move_to_edge(struct view *view, enum view_edge direction, bool snap_to_windows);
void view_grow_to_edge(struct view *view, enum view_edge direction);
void view_shrink_to_edge(struct view *view, enum view_edge direction);
void view_snap_to_edge(struct view *view, enum view_edge direction,
void view_move_to_edge(struct view *view, enum lab_edge direction, bool snap_to_windows);
void view_grow_to_edge(struct view *view, enum lab_edge direction);
void view_shrink_to_edge(struct view *view, enum lab_edge direction);
void view_snap_to_edge(struct view *view, enum lab_edge direction,
bool across_outputs, bool store_natural_geometry);
void view_snap_to_region(struct view *view, struct region *region, bool store_natural_geometry);
void view_move_to_output(struct view *view, struct output *output);
@ -673,8 +601,8 @@ void view_init(struct view *view);
void view_destroy(struct view *view);
enum view_axis view_axis_parse(const char *direction);
enum view_edge view_edge_parse(const char *direction, bool tiled, bool any);
enum view_placement_policy view_placement_parse(const char *policy);
enum lab_edge view_edge_parse(const char *direction, bool tiled, bool any);
enum lab_placement_policy view_placement_parse(const char *policy);
/* xdg.c */
struct wlr_xdg_surface *xdg_surface_from_view(struct view *view);