workspaces
This commit is contained in:
@@ -146,10 +146,21 @@ setup(absn_server *server)
|
||||
LISTEN(server->request_set_selection, request_cursor,
|
||||
server->seat->events.request_set_selection);
|
||||
|
||||
/* layer shell */
|
||||
server->layer_shell = wlr_layer_shell_v1_create(server->display, 1);
|
||||
for (int i = 0; i < LAYERS_COUNT; ++i)
|
||||
server->layers[i] = wlr_scene_tree_create(&server->scene->tree);
|
||||
|
||||
/* workspaces */
|
||||
int workspaces_count = sizeof(workspaces) / sizeof(workspaces[0]);
|
||||
server->workspaces_count = workspaces_count;
|
||||
server->workspaces = calloc(workspaces_count, sizeof(absn_workspace));
|
||||
for (int i = 0; i < workspaces_count; ++i) {
|
||||
server->workspaces[i].name = workspaces[i];
|
||||
server->workspaces[i].count = STACK_COUNT;
|
||||
server->workspaces[i].size = STACK_SIZE;
|
||||
}
|
||||
|
||||
unsetenv("DISPLAY");
|
||||
#ifdef XWAYLAND
|
||||
if ((server->xwayland = wlr_xwayland_create(server->display,
|
||||
|
||||
+50
-14
@@ -77,32 +77,68 @@ toggle_fullscreen(absn_server *server, const absn_arg *arg)
|
||||
void
|
||||
increase_master_width(absn_server *server, const absn_arg *arg)
|
||||
{
|
||||
if (!server->focused_output)
|
||||
absn_workspace *workspace = server->focused_output->workspace;
|
||||
|
||||
if (workspace->size + arg->f >= 1.0 ||
|
||||
workspace->size + arg->f <= 0.0)
|
||||
return;
|
||||
|
||||
absn_output *focus = server->focused_output;
|
||||
|
||||
if (focus->mstack_width + arg->f >= 1.0 ||
|
||||
focus->mstack_width + arg->f <= 0.0)
|
||||
return;
|
||||
|
||||
focus->mstack_width += arg->f;
|
||||
layout_arrange(focus);
|
||||
workspace->size += arg->f;
|
||||
layout_arrange(workspace->output);
|
||||
}
|
||||
|
||||
void
|
||||
increase_master_count(absn_server *server, const absn_arg *arg)
|
||||
{
|
||||
if (!server->focused_output)
|
||||
absn_workspace *workspace = server->focused_output->workspace;
|
||||
|
||||
if (workspace->count + arg->i <= 0)
|
||||
return;
|
||||
|
||||
absn_output *focus = server->focused_output;
|
||||
workspace->count += arg->i;
|
||||
layout_arrange(workspace->output);
|
||||
}
|
||||
|
||||
if (focus->mstack_count + arg->i <= 0)
|
||||
void
|
||||
switch_workspace(absn_server *server, const absn_arg *arg)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < server->workspaces_count; ++i) {
|
||||
if (arg->v == server->workspaces[i].name)
|
||||
break; /* found it */
|
||||
}
|
||||
|
||||
if (&server->workspaces[i] == server->focused_output->workspace)
|
||||
return;
|
||||
|
||||
focus->mstack_count += arg->i;
|
||||
layout_arrange(focus);
|
||||
if (!server->workspaces[i].output) {
|
||||
server->workspaces[i].output = server->focused_output;
|
||||
} else if (server->focused_output == server->workspaces[i].output) {
|
||||
server->focused_output->workspace = &server->workspaces[i];
|
||||
} else {
|
||||
server->focused_output = server->workspaces[i].output;
|
||||
|
||||
struct wlr_box *geom = &server->focused_output->geom;
|
||||
|
||||
int32_t new_x = geom->x + (geom->width / 2);
|
||||
int32_t new_y = geom->y + (geom->height / 2);
|
||||
|
||||
wlr_cursor_warp(server->cursor, NULL, new_x, new_y);
|
||||
}
|
||||
server->focused_output->workspace = &server->workspaces[i];
|
||||
|
||||
absn_toplevel *focus = NULL;
|
||||
absn_toplevel *toplevel;
|
||||
wl_list_for_each(toplevel, &server->toplevels, link)
|
||||
{
|
||||
if (toplevel && toplevel->workspace == &server->workspaces[i]) {
|
||||
focus = toplevel; /* found it */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
focus_toplevel(focus);
|
||||
layout_arrange(server->focused_output);
|
||||
}
|
||||
|
||||
noreturn void
|
||||
|
||||
+23
-18
@@ -12,11 +12,15 @@ layout_arrange(struct absn_output *output)
|
||||
int toplevels_count = 0;
|
||||
wl_list_for_each(toplevel, &output->server->toplevels, link)
|
||||
{
|
||||
if (toplevel->output == output && !toplevel->floating &&
|
||||
!toplevel->fullscreen) {
|
||||
if (toplevel->workspace == output->workspace &&
|
||||
!toplevel->floating && !toplevel->fullscreen) {
|
||||
toplevels_count++;
|
||||
wlr_scene_node_set_enabled(&toplevel->scene_tree->node,
|
||||
true);
|
||||
} else if (toplevel->output == output &&
|
||||
toplevel->workspace != output->workspace) {
|
||||
wlr_scene_node_set_enabled(&toplevel->scene_tree->node,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +33,8 @@ layout_arrange(struct absn_output *output)
|
||||
if (toplevels_count == 1) {
|
||||
wl_list_for_each(toplevel, &output->server->toplevels, link)
|
||||
{
|
||||
if (toplevel->output == output && !toplevel->floating &&
|
||||
!toplevel->fullscreen)
|
||||
if (toplevel->workspace == output->workspace &&
|
||||
!toplevel->floating && !toplevel->fullscreen)
|
||||
break;
|
||||
}
|
||||
new_geom.x = output->geom.x + og,
|
||||
@@ -45,9 +49,11 @@ layout_arrange(struct absn_output *output)
|
||||
int32_t lg = LAYOUT_GAP;
|
||||
int32_t total_lg;
|
||||
|
||||
int32_t main_stack_width = (toplevels_count <= output->mstack_count) ?
|
||||
int mcount = output->workspace->count;
|
||||
int msize = output->workspace->size;
|
||||
int32_t main_stack_width = (toplevels_count <= mcount) ?
|
||||
output->geom.width - 2 * og :
|
||||
output->mstack_width * (output->geom.width - 2 * og);
|
||||
msize * (output->geom.width - 2 * og);
|
||||
int32_t w = output->geom.width - main_stack_width - 2 * og - lg;
|
||||
|
||||
int32_t pure_h;
|
||||
@@ -58,7 +64,7 @@ layout_arrange(struct absn_output *output)
|
||||
int32_t dy = og;
|
||||
int i = 0;
|
||||
|
||||
if (toplevels_count <= output->mstack_count) {
|
||||
if (toplevels_count <= mcount) {
|
||||
total_lg = (toplevels_count - 1) * lg;
|
||||
pure_h = output->geom.height - 2 * og - total_lg;
|
||||
h = pure_h / toplevels_count;
|
||||
@@ -66,8 +72,8 @@ layout_arrange(struct absn_output *output)
|
||||
|
||||
wl_list_for_each(toplevel, &output->server->toplevels, link)
|
||||
{
|
||||
if (toplevel->output != output || toplevel->floating ||
|
||||
toplevel->fullscreen)
|
||||
if (toplevel->workspace != output->workspace ||
|
||||
toplevel->floating || toplevel->fullscreen)
|
||||
continue;
|
||||
|
||||
cur_h = h + (i < r ? 1 : 0);
|
||||
@@ -88,15 +94,15 @@ layout_arrange(struct absn_output *output)
|
||||
|
||||
wl_list_for_each(toplevel, &output->server->toplevels, link)
|
||||
{
|
||||
if (toplevel->output != output || toplevel->floating ||
|
||||
if (toplevel->workspace != output->workspace || toplevel->floating ||
|
||||
toplevel->fullscreen)
|
||||
continue;
|
||||
|
||||
if (i < output->mstack_count) {
|
||||
total_lg = (output->mstack_count - 1) * lg;
|
||||
if (i < mcount) {
|
||||
total_lg = (mcount - 1) * lg;
|
||||
pure_h = output->geom.height - 2 * og - total_lg;
|
||||
h = pure_h / output->mstack_count;
|
||||
r = pure_h % output->mstack_count;
|
||||
h = pure_h / mcount;
|
||||
r = pure_h % mcount;
|
||||
|
||||
cur_h = h + (i < r ? 1 : 0);
|
||||
|
||||
@@ -109,17 +115,16 @@ layout_arrange(struct absn_output *output)
|
||||
|
||||
dy += cur_h + lg;
|
||||
} else {
|
||||
if (i == output->mstack_count)
|
||||
if (i == mcount)
|
||||
dy = og;
|
||||
|
||||
int32_t stack_count = toplevels_count -
|
||||
output->mstack_count;
|
||||
int32_t stack_count = toplevels_count - mcount;
|
||||
total_lg = (stack_count - 1) * lg;
|
||||
pure_h = output->geom.height - 2 * og - total_lg;
|
||||
h = pure_h / stack_count;
|
||||
r = pure_h % stack_count;
|
||||
|
||||
cur_h = h + (i - output->mstack_count < r ? 1 : 0);
|
||||
cur_h = h + (i - mcount < r ? 1 : 0);
|
||||
|
||||
new_geom.x = output->geom.x + main_stack_width + lg +
|
||||
og;
|
||||
|
||||
+10
-3
@@ -46,6 +46,16 @@ new_output(struct wl_listener *listener, void *data)
|
||||
output->wlr = wlr_output;
|
||||
output->server = server;
|
||||
|
||||
for (int i = 0; i < server->workspaces_count; ++i) {
|
||||
if (!server->workspaces[i].output) {
|
||||
server->workspaces[i].output = output;
|
||||
output->workspace = &server->workspaces[i];
|
||||
output->workspace->count = STACK_COUNT;
|
||||
output->workspace->count = STACK_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LISTEN(output->frame, output_frame, wlr_output->events.frame);
|
||||
LISTEN(output->request_state, output_request_state,
|
||||
wlr_output->events.request_state);
|
||||
@@ -64,9 +74,6 @@ new_output(struct wl_listener *listener, void *data)
|
||||
scene_output);
|
||||
wlr_output_layout_get_box(server->output_layout, output->wlr,
|
||||
&output->geom);
|
||||
|
||||
output->mstack_count = MSTACK_SIZE;
|
||||
output->mstack_width = MSTACK_WIDTH;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -55,6 +55,7 @@ toplevel_map(struct wl_listener *listener, void *data)
|
||||
|
||||
update_focused_output(toplevel->server);
|
||||
toplevel->output = toplevel->server->focused_output;
|
||||
toplevel->workspace = toplevel->output->workspace;
|
||||
toplevel->fullscreen = false;
|
||||
|
||||
wl_list_insert(&toplevel->server->toplevels, &toplevel->link);
|
||||
|
||||
Reference in New Issue
Block a user