cagebreak/workspace.c
project-repo 6dbcb7eda9 Release 2.0.0
This is a major release and includes BREAKING changes!

Breaking Changes:
  * More intuitive switch of focus, next, prev and exchange (#20, 40 in Bugs.md)
    Cagebreak will probably still feel broadly the same though.
  * Remove -r flag - This is replaced by output configuration.
  * Socket disabled by default - The socket is enabled by invoking Cagebreak with the -e flag.
  * Socket permissions restricted to the user of the Cagebreak process (700)
    This may require modification of scripts interacting with the socket with
    different UIDs than the UID of the Cagebreak process.
  * Rename "Current frame" indicator to "Current tile"

Changelog:
  * Move to wlr_scene
  * Add events displaying change over the socket
    * this enables scripting tools
  * Add support for scaling outputs (thanks to Oliver Friedmann)
  * Remove -r flag
  * Add rotation to output configuration
  * Add cursor enable|disable flag
  * Add input keyboard configuration
  * Custom path flag for configuration file
  * Restrict socket permissions to the user running cagebreak (700)
  * Fix Issue #31 (resolve some terminology) 38 in Bugs.md
  * Fix Issue #30 - 39 in Bugs.md
  * Fix Issue #20 - 40 in Bugs.md
  * Fix Issue #12 - 41 in Bugs.md (dump + events over socket)
  * Fix Bugs found via scan-build static analysis (42 - 45 in Bugs.md)
  * Fix Issue #33 - 46 in Bugs.md
  * Fix Issue #32 - 47 in Bugs.md
  * Fix Issue #16 - 48 in Bugs.md
  * Fix Issue #3 - 49 in Bugs.md (disabling keybinding interpretation for specific keyboards is now possible)
  * Fix Issue #26 - 50 in Bugs.md
  * Fix Issue #7 - 51 in Bugs.md (Change cursor to square while Cagebreak is waiting for a key)
  * Fix config bug for some commands - 52 in Bugs.md
  * Fix Issue #35 - 53 in Bugs.md (update to wlroots 0.16.1)
  * Improve FAQ.md (related to some Issues)
  * Disable outputs when unable to set any mode (crashed previously)
  * Add Code of Conduct
  * Print version number on startup
2023-01-08 22:09:15 +01:00

136 lines
4 KiB
C

// Copyright 2020 - 2023, project-repo and the cagebreak contributors
// SPDX -License-Identifier: MIT
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h>
#include "message.h"
#include "output.h"
#include "seat.h"
#include "server.h"
#include "view.h"
#include "workspace.h"
void
workspace_tile_update_view(struct cg_tile *tile, struct cg_view *view) {
if(tile->view != NULL) {
wlr_scene_node_set_enabled(&tile->view->scene_tree->node, false);
tile->view->tile = NULL;
}
tile->view = view;
if(view != NULL) {
view_maximize(view, tile);
wlr_scene_node_set_enabled(&view->scene_tree->node, true);
}
}
#if CG_HAS_FANALYZE
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
#endif
int
full_screen_workspace_tiles(struct wlr_output_layout *layout,
struct wlr_output *output,
struct cg_workspace *workspace,
uint32_t *tiles_curr_id) {
workspace->focused_tile = calloc(1, sizeof(struct cg_tile));
if(!workspace->focused_tile) {
return -1;
}
workspace->focused_tile->workspace = workspace;
workspace->focused_tile->next = workspace->focused_tile;
workspace->focused_tile->prev = workspace->focused_tile;
workspace->focused_tile->tile.x = 0;
workspace->focused_tile->tile.y = 0;
struct wlr_box output_box;
wlr_output_layout_get_box(layout, output, &output_box);
workspace->focused_tile->tile.width = output_box.width;
workspace->focused_tile->tile.height = output_box.height;
workspace_tile_update_view(workspace->focused_tile, NULL);
workspace->focused_tile->id = *tiles_curr_id;
++(*tiles_curr_id);
return 0;
}
#if CG_HAS_FANALYZE
#pragma GCC diagnostic pop
#endif
struct cg_workspace *
full_screen_workspace(struct cg_output *output) {
struct cg_workspace *workspace = calloc(1, sizeof(struct cg_workspace));
if(!workspace) {
return NULL;
}
struct wlr_scene_output *scene_output =
wlr_scene_get_scene_output(output->server->scene, output->wlr_output);
if(scene_output == NULL) {
free(workspace);
return NULL;
}
workspace->server = output->server;
workspace->num = -1;
workspace->scene = wlr_scene_tree_create(&scene_output->scene->tree);
if(full_screen_workspace_tiles(output->server->output_layout,
output->wlr_output, workspace,
&output->server->tiles_curr_id) != 0) {
free(workspace);
return NULL;
}
workspace->output = output;
return workspace;
}
void
workspace_focus_tile(struct cg_workspace *ws, struct cg_tile *tile) {
ws->focused_tile = tile;
struct wlr_box *box = malloc(sizeof(struct wlr_box));
if(!box) {
wlr_log(WLR_ERROR, "Failed to allocate box required to focus tile");
return;
}
box->x = tile->tile.x + tile->tile.width / 2;
box->y = tile->tile.y + tile->tile.height / 2;
message_printf_pos(ws->output, box, CG_MESSAGE_CENTER, "Current tile");
}
void
workspace_free_tiles(struct cg_workspace *workspace) {
workspace->focused_tile->prev->next = NULL;
while(workspace->focused_tile != NULL) {
if(workspace->output->server->running &&
workspace->output->server->seat->cursor_tile ==
workspace->focused_tile) {
workspace->output->server->seat->cursor_tile = NULL;
}
struct cg_tile *next = workspace->focused_tile->next;
free(workspace->focused_tile);
workspace->focused_tile = next;
}
}
void
workspace_free(struct cg_workspace *workspace) {
workspace_free_tiles(workspace);
free(workspace);
}
void
workspace_focus(struct cg_output *outp, int ws) {
if(ws >= outp->server->nws) {
wlr_log(WLR_ERROR,
"Attempt to focus workspace %d, but only %d workspaces are "
"available.",
ws, outp->server->nws);
return;
}
wlr_scene_node_place_above(
&outp->bg->node, &outp->workspaces[outp->curr_workspace]->scene->node);
wlr_scene_node_place_above(&outp->workspaces[ws]->scene->node,
&outp->bg->node);
outp->curr_workspace = ws;
}