mirror of
https://cagebreak.project-repo.co/cagebreak.git
synced 2026-08-09 15:19:11 +02:00
Adjust focussing algorithm
* Make algorithm which picks which view to focus more stable towards
repeated insert-remove cycles.
* Improve run-time of view_get_tile
This commit is contained in:
parent
0b48dc359f
commit
89d6272775
6 changed files with 60 additions and 56 deletions
65
keybinding.c
65
keybinding.c
|
|
@ -174,7 +174,7 @@ swap_tile(struct cg_tile *tile,
|
|||
tile->view = swap_tile->view;
|
||||
swap_tile->view = tmp_view;
|
||||
if(tile->view != NULL) {
|
||||
view_maximize(tile->view, &tile->tile);
|
||||
view_maximize(tile->view, tile);
|
||||
view_damage_whole(tile->view);
|
||||
} else {
|
||||
wlr_output_damage_add_box(tile->workspace->output->damage, &tile->tile);
|
||||
|
|
@ -183,7 +183,7 @@ swap_tile(struct cg_tile *tile,
|
|||
server->curr_output->workspaces[server->curr_output->curr_workspace],
|
||||
swap_tile);
|
||||
if(swap_tile->view != NULL) {
|
||||
view_maximize(swap_tile->view, &swap_tile->tile);
|
||||
view_maximize(swap_tile->view, swap_tile);
|
||||
view_damage_whole(swap_tile->view);
|
||||
} else {
|
||||
wlr_output_damage_add_box(tile->workspace->output->damage, &tile->tile);
|
||||
|
|
@ -342,7 +342,7 @@ resize(struct cg_tile *tile, const struct cg_tile *parent, int coord_offset,
|
|||
.height = tile->tile.y == 0 ? tile->tile.height : coord_offset};
|
||||
wlr_output_damage_add_box(tile->workspace->output->damage, &damage_box);
|
||||
if(tile->view != NULL) {
|
||||
view_maximize(tile->view, &tile->tile);
|
||||
view_maximize(tile->view, tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -456,6 +456,11 @@ keybinding_workspace_fullscreen(struct cg_server *server) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct cg_view *it_view;
|
||||
wl_list_for_each(it_view, &output->workspaces[output->curr_workspace]->views, link) {
|
||||
it_view->tile=output->workspaces[output->curr_workspace]->focused_tile;
|
||||
}
|
||||
|
||||
seat_set_focus(server->seat, current_view);
|
||||
}
|
||||
|
||||
|
|
@ -537,11 +542,11 @@ keybinding_split_output(struct cg_output *output, bool vertical) {
|
|||
workspace_focus_tile(curr_workspace, curr_workspace->focused_tile);
|
||||
|
||||
if(next_view != NULL) {
|
||||
view_maximize(next_view, &new_tile->tile);
|
||||
view_maximize(next_view, new_tile);
|
||||
}
|
||||
|
||||
if(original_view != NULL) {
|
||||
view_maximize(original_view, &curr_workspace->focused_tile->tile);
|
||||
view_maximize(original_view, curr_workspace->focused_tile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -601,43 +606,39 @@ keybinding_cycle_views(struct cg_server *server, bool reverse) {
|
|||
server->curr_output->workspaces[server->curr_output->curr_workspace];
|
||||
struct cg_view *current_view = curr_workspace->focused_tile->view;
|
||||
|
||||
struct cg_view *new_view;
|
||||
// We are focused on the desktop
|
||||
if(current_view == NULL) {
|
||||
current_view = wl_container_of(&curr_workspace->views, new_view, link);
|
||||
if(reverse) {
|
||||
new_view =
|
||||
wl_container_of(curr_workspace->views.prev, new_view, link);
|
||||
} else {
|
||||
new_view =
|
||||
wl_container_of(curr_workspace->views.next, new_view, link);
|
||||
struct cg_view *tmp_view, *next_view=NULL;
|
||||
if(reverse) {
|
||||
wl_list_for_each_reverse(tmp_view, &curr_workspace->views, link) {
|
||||
if(tmp_view == current_view) {
|
||||
continue;
|
||||
}
|
||||
if(!view_is_visible(tmp_view)) {
|
||||
next_view=tmp_view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(reverse) {
|
||||
new_view = wl_container_of(current_view->link.prev, new_view, link);
|
||||
} else {
|
||||
new_view = wl_container_of(current_view->link.next, new_view, link);
|
||||
wl_list_for_each(tmp_view, &curr_workspace->views, link) {
|
||||
if(tmp_view == current_view) {
|
||||
continue;
|
||||
}
|
||||
if(!view_is_visible(tmp_view)) {
|
||||
next_view=tmp_view;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(&new_view->link != ¤t_view->link &&
|
||||
(&new_view->link == &curr_workspace->views ||
|
||||
view_is_visible(new_view))) {
|
||||
if(reverse) {
|
||||
new_view = wl_container_of(new_view->link.prev, new_view, link);
|
||||
} else {
|
||||
new_view = wl_container_of(new_view->link.next, new_view, link);
|
||||
}
|
||||
}
|
||||
if(&new_view->link == &curr_workspace->views) {
|
||||
|
||||
if(next_view == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_output_damage_add_box(curr_workspace->output->damage,
|
||||
&curr_workspace->focused_tile->tile);
|
||||
seat_set_focus(server->seat, new_view);
|
||||
seat_set_focus(server->seat, next_view);
|
||||
/* Move the previous view to the end of the list unless we are focused on
|
||||
* the desktop*/
|
||||
if(!reverse && ¤t_view->link != &curr_workspace->views) {
|
||||
if(!reverse && current_view != NULL) {
|
||||
wl_list_remove(¤t_view->link);
|
||||
wl_list_insert(curr_workspace->views.prev, ¤t_view->link);
|
||||
}
|
||||
|
|
@ -824,7 +825,7 @@ keybinding_move_view_to_workspace(struct cg_server *server, uint32_t ws) {
|
|||
view->workspace = ws;
|
||||
wl_list_insert(&ws->views, &view->link);
|
||||
ws->focused_tile->view = view;
|
||||
view_maximize(view, &ws->focused_tile->tile);
|
||||
view_maximize(view, ws->focused_tile);
|
||||
seat_set_focus(server->seat, view);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
output.c
6
output.c
|
|
@ -429,6 +429,9 @@ output_clear(struct cg_output *output) {
|
|||
view->workspace =
|
||||
server->curr_output
|
||||
->workspaces[server->curr_output->curr_workspace];
|
||||
view->tile =
|
||||
server->curr_output
|
||||
->workspaces[server->curr_output->curr_workspace]->focused_tile;
|
||||
if(server->seat->focused_view == NULL) {
|
||||
seat_set_focus(server->seat, view);
|
||||
}
|
||||
|
|
@ -448,6 +451,9 @@ output_clear(struct cg_output *output) {
|
|||
view->workspace =
|
||||
server->curr_output
|
||||
->workspaces[server->curr_output->curr_workspace];
|
||||
view->tile =
|
||||
server->curr_output
|
||||
->workspaces[server->curr_output->curr_workspace]->focused_tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
render.c
1
render.c
|
|
@ -135,7 +135,6 @@ render_view_toplevels(struct cg_view *view, struct cg_output *output,
|
|||
.tile_width = 0,
|
||||
.tile_height = 0,
|
||||
};
|
||||
// TODO: improve run time behaviour of view_get_tile
|
||||
struct cg_tile *view_tile = view_get_tile(view);
|
||||
if(view_tile != NULL) {
|
||||
if(view_tile->tile.width != view->wlr_surface->current.width ||
|
||||
|
|
|
|||
8
seat.c
8
seat.c
|
|
@ -965,9 +965,13 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) {
|
|||
struct cg_workspace *curr_workspace =
|
||||
server->curr_output
|
||||
->workspaces[server->curr_output->curr_workspace];
|
||||
view_maximize(view, &curr_workspace->focused_tile->tile);
|
||||
view_maximize(view, curr_workspace->focused_tile);
|
||||
wl_list_remove(&view->link);
|
||||
wl_list_insert(&curr_workspace->views, &view->link);
|
||||
if(curr_workspace->focused_tile->view != NULL) {
|
||||
wl_list_insert(&curr_workspace->focused_tile->view->link,&view->link);
|
||||
} else {
|
||||
wl_list_insert(curr_workspace->views.prev,&view->link);
|
||||
}
|
||||
curr_workspace->focused_tile->view = view;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
view.c
33
view.c
|
|
@ -197,15 +197,11 @@ view_is_primary(const struct cg_view *view) {
|
|||
struct cg_tile *
|
||||
view_get_tile(const struct cg_view *view) {
|
||||
|
||||
bool first = true;
|
||||
for(struct cg_tile *tile = view->workspace->focused_tile;
|
||||
first || view->workspace->focused_tile != tile; tile = tile->next) {
|
||||
first = false;
|
||||
if(tile->view == view) {
|
||||
return tile;
|
||||
}
|
||||
if(view->tile != NULL && view->tile->view == view) {
|
||||
return view->tile;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -224,7 +220,7 @@ view_damage(struct cg_view *view, bool whole) {
|
|||
if(view_tile != NULL &&
|
||||
(view->wlr_surface->current.width != view_tile->tile.width ||
|
||||
view->wlr_surface->current.height != view_tile->tile.height)) {
|
||||
view_maximize(view, &view_tile->tile);
|
||||
view_maximize(view, view_tile);
|
||||
}
|
||||
output_damage_surface(view->workspace->output, view->wlr_surface, view->ox,
|
||||
view->oy, whole);
|
||||
|
|
@ -248,20 +244,16 @@ view_activate(struct cg_view *view, bool activate) {
|
|||
}
|
||||
|
||||
void
|
||||
view_maximize(struct cg_view *view, const struct wlr_box *tile_box) {
|
||||
view->ox = tile_box->x;
|
||||
view->oy = tile_box->y;
|
||||
view->impl->maximize(view, tile_box->width, tile_box->height);
|
||||
view_maximize(struct cg_view *view, struct cg_tile *tile) {
|
||||
view->ox = tile->tile.x;
|
||||
view->oy = tile->tile.y;
|
||||
view->impl->maximize(view, tile->tile.width, tile->tile.height);
|
||||
view->tile=tile;
|
||||
}
|
||||
|
||||
void
|
||||
view_position(struct cg_view *view) {
|
||||
struct wlr_box *tile_workspace_box =
|
||||
&view->workspace->output
|
||||
->workspaces[view->workspace->output->curr_workspace]
|
||||
->focused_tile->tile;
|
||||
|
||||
view_maximize(view, tile_workspace_box);
|
||||
view_maximize(view, view->workspace->output->workspaces[view->workspace->output->curr_workspace]->focused_tile);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -309,7 +301,7 @@ view_unmap(struct cg_view *view) {
|
|||
&view_tile->tile);
|
||||
view_tile->view = prev;
|
||||
if(prev != NULL) {
|
||||
view_maximize(prev, &view_tile->tile);
|
||||
view_maximize(prev, view_tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -384,6 +376,7 @@ void
|
|||
view_init(struct cg_view *view, enum cg_view_type type,
|
||||
const struct cg_view_impl *impl, struct cg_server *server) {
|
||||
view->workspace = NULL;
|
||||
view->tile = NULL;
|
||||
view->server = server;
|
||||
view->type = type;
|
||||
view->impl = impl;
|
||||
|
|
|
|||
3
view.h
3
view.h
|
|
@ -23,6 +23,7 @@ struct cg_view {
|
|||
struct wl_list link; // server::views
|
||||
struct wl_list children; // cg_view_child::link
|
||||
struct wlr_surface *wlr_surface;
|
||||
struct cg_tile *tile;
|
||||
|
||||
/* The view has a position in output coordinates. */
|
||||
int ox, oy;
|
||||
|
|
@ -100,7 +101,7 @@ view_for_each_popup(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
|||
void
|
||||
view_unmap(struct cg_view *view);
|
||||
void
|
||||
view_maximize(struct cg_view *view, const struct wlr_box *tile_box);
|
||||
view_maximize(struct cg_view *view, struct cg_tile *tile);
|
||||
void
|
||||
view_map(struct cg_view *view, struct wlr_surface *surface,
|
||||
struct cg_workspace *ws);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue