tree-wide: auto-replace of (struct server *)

#!/bin/bash
    read -r -d '' EXPRS << EOF
    s/xwayland->server/xwayland->svr/g;

    s/\t*struct server \*server;\n//g;
    s/\t*struct server \*server =.*?;\n//gs;
    s/\t*.* = ([a-z_]*->)*server[;,]\n//g;
    s/\{\n\n/\{\n/g;
    s/\n\n+/\n\n/g;

    s/\(\s*struct server \*server\)/(void)/g;
    s/\(\s*struct server \*server,\s*/(/g;
    s/,\s*struct server \*server\)/)/g;
    s/,\s*struct server \*server,\s*/, /g;

    s/\(\s*([a-z_]*->)*server\)/()/g;
    s/\(\s*([a-z_]*->)*server,\s*/(/g;
    s/,\s*([a-z_]*->)*server\)/)/g;
    s/,\s*([a-z_]*->)*server,\s*/, /g;

    s/([a-z_]*->)*server->/g_server./g;

    s/xwayland->svr/xwayland->server/g;
    EOF

    find src include \( -name \*.c -o -name \*.h \) -exec \
        perl -0777 -i -pe "$EXPRS" \{\} \;
This commit is contained in:
John Lindgren 2026-02-23 11:56:39 -05:00 committed by Johan Malm
parent 60ac8f07bb
commit cb49bddf63
81 changed files with 1522 additions and 1682 deletions

View file

@ -62,9 +62,9 @@ parse_workspace_index(const char *name)
}
static void
_osd_update(struct server *server)
_osd_update(void)
{
struct theme *theme = server->theme;
struct theme *theme = g_server.theme;
/* Settings */
uint16_t margin = 10;
@ -75,7 +75,7 @@ _osd_update(struct server *server)
theme->osd_workspace_switcher_boxes_height == 0;
/* Dimensions */
size_t workspace_count = wl_list_length(&server->workspaces.all);
size_t workspace_count = wl_list_length(&g_server.workspaces.all);
uint16_t marker_width = workspace_count * (rect_width + padding) - padding;
uint16_t width = margin * 2 + (marker_width < 200 ? 200 : marker_width);
uint16_t height = margin * (hide_boxes ? 2 : 3) + rect_height + font_height(&rc.font_osd);
@ -85,7 +85,7 @@ _osd_update(struct server *server)
struct workspace *workspace;
struct output *output;
wl_list_for_each(output, &server->outputs, link) {
wl_list_for_each(output, &g_server.outputs, link) {
if (!output_is_usable(output)) {
continue;
}
@ -115,9 +115,9 @@ _osd_update(struct server *server)
uint16_t x;
if (!hide_boxes) {
x = (width - marker_width) / 2;
wl_list_for_each(workspace, &server->workspaces.all, link) {
bool active = workspace == server->workspaces.current;
set_cairo_color(cairo, server->theme->osd_label_text_color);
wl_list_for_each(workspace, &g_server.workspaces.all, link) {
bool active = workspace == g_server.workspaces.current;
set_cairo_color(cairo, g_server.theme->osd_label_text_color);
struct wlr_fbox fbox = {
.x = x,
.y = margin,
@ -136,13 +136,13 @@ _osd_update(struct server *server)
}
/* Text */
set_cairo_color(cairo, server->theme->osd_label_text_color);
set_cairo_color(cairo, g_server.theme->osd_label_text_color);
PangoLayout *layout = pango_cairo_create_layout(cairo);
pango_context_set_round_glyph_positions(pango_layout_get_context(layout), false);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
/* Center workspace indicator on the x axis */
int req_width = font_width(&rc.font_osd, server->workspaces.current->name);
int req_width = font_width(&rc.font_osd, g_server.workspaces.current->name);
req_width = MIN(req_width, width - 2 * margin);
x = (width - req_width) / 2;
if (!hide_boxes) {
@ -155,7 +155,7 @@ _osd_update(struct server *server)
pango_layout_set_font_description(layout, desc);
pango_layout_set_width(layout, req_width * PANGO_SCALE);
pango_font_description_free(desc);
pango_layout_set_text(layout, server->workspaces.current->name, -1);
pango_layout_set_text(layout, g_server.workspaces.current->name, -1);
pango_cairo_show_layout(cairo, layout);
g_object_unref(layout);
@ -165,11 +165,11 @@ _osd_update(struct server *server)
if (!output->workspace_osd) {
output->workspace_osd = lab_wlr_scene_buffer_create(
&server->scene->tree, NULL);
&g_server.scene->tree, NULL);
}
/* Position the whole thing */
struct wlr_box output_box;
wlr_output_layout_get_box(output->server->output_layout,
wlr_output_layout_get_box(g_server.output_layout,
output->wlr_output, &output_box);
int lx = output_box.x + (output_box.width - width) / 2;
int ly = output_box.y + (output_box.height - height) / 2;
@ -184,7 +184,7 @@ _osd_update(struct server *server)
}
static struct workspace *
workspace_find_by_name(struct server *server, const char *name)
workspace_find_by_name(const char *name)
{
struct workspace *workspace;
@ -192,7 +192,7 @@ workspace_find_by_name(struct server *server, const char *name)
size_t parsed_index = parse_workspace_index(name);
if (parsed_index) {
size_t index = 0;
wl_list_for_each(workspace, &server->workspaces.all, link) {
wl_list_for_each(workspace, &g_server.workspaces.all, link) {
if (parsed_index == ++index) {
return workspace;
}
@ -200,7 +200,7 @@ workspace_find_by_name(struct server *server, const char *name)
}
/* by name */
wl_list_for_each(workspace, &server->workspaces.all, link) {
wl_list_for_each(workspace, &g_server.workspaces.all, link) {
if (!strcmp(workspace->name, name)) {
return workspace;
}
@ -230,23 +230,22 @@ handle_ext_workspace_activate(struct wl_listener *listener, void *data)
/* Internal API */
static void
add_workspace(struct server *server, const char *name)
add_workspace(const char *name)
{
struct workspace *workspace = znew(*workspace);
workspace->server = server;
workspace->name = xstrdup(name);
workspace->tree = lab_wlr_scene_tree_create(server->workspace_tree);
workspace->tree = lab_wlr_scene_tree_create(g_server.workspace_tree);
workspace->view_trees[VIEW_LAYER_ALWAYS_ON_BOTTOM] =
lab_wlr_scene_tree_create(workspace->tree);
workspace->view_trees[VIEW_LAYER_NORMAL] =
lab_wlr_scene_tree_create(workspace->tree);
workspace->view_trees[VIEW_LAYER_ALWAYS_ON_TOP] =
lab_wlr_scene_tree_create(workspace->tree);
wl_list_append(&server->workspaces.all, &workspace->link);
wl_list_append(&g_server.workspaces.all, &workspace->link);
wlr_scene_node_set_enabled(&workspace->tree->node, false);
/* cosmic */
workspace->cosmic_workspace = lab_cosmic_workspace_create(server->workspaces.cosmic_group);
workspace->cosmic_workspace = lab_cosmic_workspace_create(g_server.workspaces.cosmic_group);
lab_cosmic_workspace_set_name(workspace->cosmic_workspace, name);
workspace->on_cosmic.activate.notify = handle_cosmic_workspace_activate;
@ -255,8 +254,8 @@ add_workspace(struct server *server, const char *name)
/* ext */
workspace->ext_workspace = lab_ext_workspace_create(
server->workspaces.ext_manager, /*id*/ NULL);
lab_ext_workspace_assign_to_group(workspace->ext_workspace, server->workspaces.ext_group);
g_server.workspaces.ext_manager, /*id*/ NULL);
lab_ext_workspace_assign_to_group(workspace->ext_workspace, g_server.workspaces.ext_group);
lab_ext_workspace_set_name(workspace->ext_workspace, name);
workspace->on_ext.activate.notify = handle_ext_workspace_activate;
@ -295,11 +294,11 @@ get_next(struct workspace *current, struct wl_list *workspaces, bool wrap)
}
static bool
workspace_has_views(struct workspace *workspace, struct server *server)
workspace_has_views(struct workspace *workspace)
{
struct view *view;
for_each_view(view, &server->views, LAB_VIEW_CRITERIA_NO_OMNIPRESENT) {
for_each_view(view, &g_server.views, LAB_VIEW_CRITERIA_NO_OMNIPRESENT) {
if (view->workspace == workspace) {
return true;
}
@ -311,7 +310,6 @@ static struct workspace *
get_adjacent_occupied(struct workspace *current, struct wl_list *workspaces,
bool wrap, bool reverse)
{
struct server *server = current->server;
struct wl_list *start = &current->link;
struct wl_list *link = reverse ? start->prev : start->next;
bool has_wrapped = false;
@ -340,7 +338,7 @@ get_adjacent_occupied(struct workspace *current, struct wl_list *workspaces,
}
/* Check if it's occupied (and not current) */
if (target != current && workspace_has_views(target, server)) {
if (target != current && workspace_has_views(target)) {
return target;
}
@ -373,56 +371,56 @@ _osd_handle_timeout(void *data)
}
static void
_osd_show(struct server *server)
_osd_show(void)
{
if (!rc.workspace_config.popuptime) {
return;
}
_osd_update(server);
_osd_update();
struct output *output;
wl_list_for_each(output, &server->outputs, link) {
wl_list_for_each(output, &g_server.outputs, link) {
if (output_is_usable(output) && output->workspace_osd) {
wlr_scene_node_set_enabled(&output->workspace_osd->node, true);
}
}
if (keyboard_get_all_modifiers(&server->seat)) {
if (keyboard_get_all_modifiers(&g_server.seat)) {
/* Hidden by release of all modifiers */
server->seat.workspace_osd_shown_by_modifier = true;
g_server.seat.workspace_osd_shown_by_modifier = true;
} else {
/* Hidden by timer */
if (!server->seat.workspace_osd_timer) {
server->seat.workspace_osd_timer = wl_event_loop_add_timer(
server->wl_event_loop, _osd_handle_timeout, &server->seat);
if (!g_server.seat.workspace_osd_timer) {
g_server.seat.workspace_osd_timer = wl_event_loop_add_timer(
g_server.wl_event_loop, _osd_handle_timeout, &g_server.seat);
}
wl_event_source_timer_update(server->seat.workspace_osd_timer,
wl_event_source_timer_update(g_server.seat.workspace_osd_timer,
rc.workspace_config.popuptime);
}
}
/* Public API */
void
workspaces_init(struct server *server)
workspaces_init(void)
{
server->workspaces.cosmic_manager = lab_cosmic_workspace_manager_create(
server->wl_display, /* capabilities */ CW_CAP_WS_ACTIVATE,
g_server.workspaces.cosmic_manager = lab_cosmic_workspace_manager_create(
g_server.wl_display, /* capabilities */ CW_CAP_WS_ACTIVATE,
COSMIC_WORKSPACES_VERSION);
server->workspaces.ext_manager = lab_ext_workspace_manager_create(
server->wl_display, /* capabilities */ WS_CAP_WS_ACTIVATE,
g_server.workspaces.ext_manager = lab_ext_workspace_manager_create(
g_server.wl_display, /* capabilities */ WS_CAP_WS_ACTIVATE,
EXT_WORKSPACES_VERSION);
server->workspaces.cosmic_group = lab_cosmic_workspace_group_create(
server->workspaces.cosmic_manager);
g_server.workspaces.cosmic_group = lab_cosmic_workspace_group_create(
g_server.workspaces.cosmic_manager);
server->workspaces.ext_group = lab_ext_workspace_group_create(
server->workspaces.ext_manager);
g_server.workspaces.ext_group = lab_ext_workspace_group_create(
g_server.workspaces.ext_manager);
wl_list_init(&server->workspaces.all);
wl_list_init(&g_server.workspaces.all);
struct workspace_config *conf;
wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
add_workspace(server, conf->name);
add_workspace(conf->name);
}
/*
@ -432,16 +430,16 @@ workspaces_init(struct server *server)
char *initial_name = rc.workspace_config.initial_workspace_name;
struct workspace *initial = NULL;
struct workspace *first = wl_container_of(
server->workspaces.all.next, first, link);
g_server.workspaces.all.next, first, link);
if (initial_name) {
initial = workspace_find_by_name(server, initial_name);
initial = workspace_find_by_name(initial_name);
}
if (!initial) {
initial = first;
}
server->workspaces.current = initial;
g_server.workspaces.current = initial;
wlr_scene_node_set_enabled(&initial->tree->node, true);
lab_cosmic_workspace_set_active(initial->cosmic_workspace, true);
lab_ext_workspace_set_active(initial->ext_workspace, true);
@ -456,19 +454,18 @@ void
workspaces_switch_to(struct workspace *target, bool update_focus)
{
assert(target);
struct server *server = target->server;
if (target == server->workspaces.current) {
if (target == g_server.workspaces.current) {
return;
}
/* Disable the old workspace */
wlr_scene_node_set_enabled(
&server->workspaces.current->tree->node, false);
&g_server.workspaces.current->tree->node, false);
lab_cosmic_workspace_set_active(
server->workspaces.current->cosmic_workspace, false);
g_server.workspaces.current->cosmic_workspace, false);
lab_ext_workspace_set_active(
server->workspaces.current->ext_workspace, false);
g_server.workspaces.current->ext_workspace, false);
/*
* Move Omnipresent views to new workspace.
@ -476,7 +473,7 @@ workspaces_switch_to(struct workspace *target, bool update_focus)
* view_is_focusable() returns false (e.g. Conky).
*/
struct view *view;
wl_list_for_each_reverse(view, &server->views, link) {
wl_list_for_each_reverse(view, &g_server.views, link) {
if (view->visible_on_all_workspaces) {
view_move_to_workspace(view, target);
}
@ -486,12 +483,12 @@ workspaces_switch_to(struct workspace *target, bool update_focus)
wlr_scene_node_set_enabled(&target->tree->node, true);
/* Save the last visited workspace */
server->workspaces.last = server->workspaces.current;
g_server.workspaces.last = g_server.workspaces.current;
/* Make sure new views will spawn on the new workspace */
server->workspaces.current = target;
g_server.workspaces.current = target;
struct view *grabbed_view = server->grabbed_view;
struct view *grabbed_view = g_server.grabbed_view;
if (grabbed_view) {
view_move_to_workspace(grabbed_view, target);
}
@ -501,23 +498,23 @@ workspaces_switch_to(struct workspace *target, bool update_focus)
* the focus is not already on an omnipresent view.
*/
if (update_focus) {
struct view *active_view = server->active_view;
struct view *active_view = g_server.active_view;
if (!(active_view && active_view->visible_on_all_workspaces)) {
desktop_focus_topmost_view(server);
desktop_focus_topmost_view();
}
}
/* And finally show the OSD */
_osd_show(server);
_osd_show();
/*
* Make sure we are not carrying around a
* cursor image from the previous desktop
*/
cursor_update_focus(server);
cursor_update_focus();
/* Ensure that only currently visible fullscreen windows hide the top layer */
desktop_update_top_layer_visibility(server);
desktop_update_top_layer_visibility();
lab_cosmic_workspace_set_active(target->cosmic_workspace, true);
lab_ext_workspace_set_active(target->ext_workspace, true);
@ -528,8 +525,7 @@ workspaces_osd_hide(struct seat *seat)
{
assert(seat);
struct output *output;
struct server *server = seat->server;
wl_list_for_each(output, &server->outputs, link) {
wl_list_for_each(output, &g_server.outputs, link) {
if (!output->workspace_osd) {
continue;
}
@ -539,7 +535,7 @@ workspaces_osd_hide(struct seat *seat)
seat->workspace_osd_shown_by_modifier = false;
/* Update the cursor focus in case it was on top of the OSD before */
cursor_update_focus(server);
cursor_update_focus();
}
struct workspace *
@ -549,13 +545,12 @@ workspaces_find(struct workspace *anchor, const char *name, bool wrap)
if (!name) {
return NULL;
}
struct server *server = anchor->server;
struct wl_list *workspaces = &server->workspaces.all;
struct wl_list *workspaces = &g_server.workspaces.all;
if (!strcasecmp(name, "current")) {
return anchor;
} else if (!strcasecmp(name, "last")) {
return server->workspaces.last;
return g_server.workspaces.last;
} else if (!strcasecmp(name, "left")) {
return get_prev(anchor, workspaces, wrap);
} else if (!strcasecmp(name, "right")) {
@ -565,7 +560,7 @@ workspaces_find(struct workspace *anchor, const char *name, bool wrap)
} else if (!strcasecmp(name, "right-occupied")) {
return get_next_occupied(anchor, workspaces, wrap);
}
return workspace_find_by_name(server, name);
return workspace_find_by_name(name);
}
static void
@ -583,7 +578,7 @@ destroy_workspace(struct workspace *workspace)
}
void
workspaces_reconfigure(struct server *server)
workspaces_reconfigure(void)
{
/*
* Compare actual workspace list with the new desired configuration to:
@ -592,18 +587,18 @@ workspaces_reconfigure(struct server *server)
* - Destroy workspaces if fewer workspace are desired
*/
struct wl_list *workspace_link = server->workspaces.all.next;
struct wl_list *workspace_link = g_server.workspaces.all.next;
struct workspace_config *conf;
wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
struct workspace *workspace = wl_container_of(
workspace_link, workspace, link);
if (workspace_link == &server->workspaces.all) {
if (workspace_link == &g_server.workspaces.all) {
/* # of configured workspaces increased */
wlr_log(WLR_DEBUG, "Adding workspace \"%s\"",
conf->name);
add_workspace(server, conf->name);
add_workspace(conf->name);
continue;
}
if (strcmp(workspace->name, conf->name)) {
@ -619,16 +614,16 @@ workspaces_reconfigure(struct server *server)
workspace_link = workspace_link->next;
}
if (workspace_link == &server->workspaces.all) {
if (workspace_link == &g_server.workspaces.all) {
return;
}
/* # of configured workspaces decreased */
overlay_finish(&server->seat);
overlay_finish(&g_server.seat);
struct workspace *first_workspace =
wl_container_of(server->workspaces.all.next, first_workspace, link);
wl_container_of(g_server.workspaces.all.next, first_workspace, link);
while (workspace_link != &server->workspaces.all) {
while (workspace_link != &g_server.workspaces.all) {
struct workspace *workspace = wl_container_of(
workspace_link, workspace, link);
@ -636,18 +631,18 @@ workspaces_reconfigure(struct server *server)
workspace->name);
struct view *view;
wl_list_for_each(view, &server->views, link) {
wl_list_for_each(view, &g_server.views, link) {
if (view->workspace == workspace) {
view_move_to_workspace(view, first_workspace);
}
}
if (server->workspaces.current == workspace) {
if (g_server.workspaces.current == workspace) {
workspaces_switch_to(first_workspace,
/* update_focus */ true);
}
if (server->workspaces.last == workspace) {
server->workspaces.last = first_workspace;
if (g_server.workspaces.last == workspace) {
g_server.workspaces.last = first_workspace;
}
workspace_link = workspace_link->next;
@ -656,11 +651,11 @@ workspaces_reconfigure(struct server *server)
}
void
workspaces_destroy(struct server *server)
workspaces_destroy(void)
{
struct workspace *workspace, *tmp;
wl_list_for_each_safe(workspace, tmp, &server->workspaces.all, link) {
wl_list_for_each_safe(workspace, tmp, &g_server.workspaces.all, link) {
destroy_workspace(workspace);
}
assert(wl_list_empty(&server->workspaces.all));
assert(wl_list_empty(&g_server.workspaces.all));
}