diff --git a/cagebreak.c b/cagebreak.c index 59fb4f1..b5e1f9f 100644 --- a/cagebreak.c +++ b/cagebreak.c @@ -16,29 +16,29 @@ #include #include #include -#include #include +#include #include -#include #include +#include #include -#include #include #include #include #include #include -#include #include #include #include #include -#include -#include #include #include +#include +#include +#include #include #include +#include #if CG_HAS_XWAYLAND #include #endif @@ -226,6 +226,7 @@ get_config_file() { int main(int argc, char *argv[]) { + printf("This is cagebreak, version %s\n", CG_VERSION); struct cg_server server = {0}; struct wl_event_loop *event_loop = NULL; struct wl_event_source *sigint_source = NULL; @@ -340,14 +341,15 @@ main(int argc, char *argv[]) { } server.renderer = wlr_renderer_autocreate(backend); - if (!server.renderer) { + if(!server.renderer) { wlr_log(WLR_ERROR, "Unable to create the wlroots renderer"); ret = 1; goto end; } - server.allocator = wlr_allocator_autocreate(server.backend, server.renderer); - if (!server.allocator) { + server.allocator = + wlr_allocator_autocreate(server.backend, server.renderer); + if(!server.allocator) { wlr_log(WLR_ERROR, "Unable to create the wlroots allocator"); ret = 1; goto end; @@ -355,7 +357,7 @@ main(int argc, char *argv[]) { wlr_renderer_init_wl_display(server.renderer, server.wl_display); - server.bg_color = (float[4]){0, 0, 1, 1}; + server.bg_color = (float[4]){0, 0, 0, 1}; wl_list_init(&server.outputs); wl_list_init(&server.disabled_outputs); @@ -373,7 +375,7 @@ main(int argc, char *argv[]) { } server.scene = wlr_scene_create(); - if (!server.scene) { + if(!server.scene) { wlr_log(WLR_ERROR, "Unable to create scene"); ret = 1; goto end; @@ -467,28 +469,28 @@ main(int argc, char *argv[]) { server_decoration_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); viewporter = wlr_viewporter_create(server.wl_display); - if (!viewporter) { + if(!viewporter) { wlr_log(WLR_ERROR, "Unable to create the viewporter interface"); ret = 1; goto end; } presentation = wlr_presentation_create(server.wl_display, server.backend); - if (!presentation) { + if(!presentation) { wlr_log(WLR_ERROR, "Unable to create the presentation interface"); ret = 1; goto end; } wlr_scene_set_presentation(server.scene, presentation); - export_dmabuf_manager = wlr_export_dmabuf_manager_v1_create(server.wl_display); - if (!export_dmabuf_manager) { + export_dmabuf_manager = + wlr_export_dmabuf_manager_v1_create(server.wl_display); + if(!export_dmabuf_manager) { wlr_log(WLR_ERROR, "Unable to create the export DMABUF manager"); ret = 1; goto end; } - screencopy_manager = wlr_screencopy_manager_v1_create(server.wl_display); if(!screencopy_manager) { wlr_log(WLR_ERROR, "Unable to create the screencopy manager"); @@ -505,7 +507,8 @@ main(int argc, char *argv[]) { } if(!wlr_primary_selection_v1_device_manager_create(server.wl_display)) { - wlr_log(WLR_ERROR, "Unable to create the primary selection device manager"); + wlr_log(WLR_ERROR, + "Unable to create the primary selection device manager"); ret = 1; goto end; } diff --git a/ipc_server.c b/ipc_server.c index 86560b9..0125e5e 100644 --- a/ipc_server.c +++ b/ipc_server.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,7 @@ ipc_init(struct cg_server *server) { return -1; } + chmod(ipc->sockaddr->sun_path, 0700); setenv("CAGEBREAK_SOCKET", ipc->sockaddr->sun_path, 1); wl_list_init(&ipc->client_list); @@ -311,7 +313,7 @@ ipc_client_handle_command(struct cg_ipc_client *client) { offset = (nl_pos - client->read_buffer) + 1; } if(offset == 0) { - wlr_log(WLR_ERROR, "Line received was longer that %d, discarding it", + wlr_log(WLR_ERROR, "Line received was longer than %d, discarding it", MAX_LINE_SIZE); client->read_buf_len = 0; client->read_discard = 1; diff --git a/keybinding.c b/keybinding.c index 2cca163..afe5609 100644 --- a/keybinding.c +++ b/keybinding.c @@ -1,25 +1,25 @@ #define _POSIX_C_SOURCE 200809L #include -#include #include +#include #include #include #include +#include #include #include -#include #include #include #include "input.h" -#include "util.h" #include "input_manager.h" #include "keybinding.h" #include "message.h" #include "output.h" #include "seat.h" #include "server.h" +#include "util.h" #include "view.h" #include "workspace.h" @@ -145,10 +145,12 @@ is_between_strict(int a, int b, int x) { struct cg_tile * find_right_tile(const struct cg_tile *tile) { struct cg_tile *it = tile->next; - int center=tile->tile.y+tile->tile.height/2; + int center = tile->tile.y + tile->tile.height / 2; while(it != tile) { - if(it->tile.x== tile->tile.x+tile->tile.width) { - if(is_between_strict(it->tile.y,it->tile.y+it->tile.height,center)||it->tile.y+it->tile.height==center) { + if(it->tile.x == tile->tile.x + tile->tile.width) { + if(is_between_strict(it->tile.y, it->tile.y + it->tile.height, + center) || + it->tile.y + it->tile.height == center) { return it; } } @@ -160,10 +162,12 @@ find_right_tile(const struct cg_tile *tile) { struct cg_tile * find_left_tile(const struct cg_tile *tile) { struct cg_tile *it = tile->next; - int center=tile->tile.y+tile->tile.height/2; + int center = tile->tile.y + tile->tile.height / 2; while(it != tile) { - if(it->tile.x+it->tile.width == tile->tile.x) { - if(is_between_strict(it->tile.y,it->tile.y+it->tile.height,center)||it->tile.y+it->tile.height==center) { + if(it->tile.x + it->tile.width == tile->tile.x) { + if(is_between_strict(it->tile.y, it->tile.y + it->tile.height, + center) || + it->tile.y + it->tile.height == center) { return it; } } @@ -175,10 +179,12 @@ find_left_tile(const struct cg_tile *tile) { struct cg_tile * find_top_tile(const struct cg_tile *tile) { struct cg_tile *it = tile->next; - int center=tile->tile.x+tile->tile.width/2; + int center = tile->tile.x + tile->tile.width / 2; while(it != tile) { - if(it->tile.y+it->tile.height == tile->tile.y) { - if(is_between_strict(it->tile.x,it->tile.x+it->tile.width,center)||it->tile.x+it->tile.width==center) { + if(it->tile.y + it->tile.height == tile->tile.y) { + if(is_between_strict(it->tile.x, it->tile.x + it->tile.width, + center) || + it->tile.x + it->tile.width == center) { return it; } } @@ -190,10 +196,12 @@ find_top_tile(const struct cg_tile *tile) { struct cg_tile * find_bottom_tile(const struct cg_tile *tile) { struct cg_tile *it = tile->next; - int center=tile->tile.x+tile->tile.width/2; + int center = tile->tile.x + tile->tile.width / 2; while(it != tile) { - if(it->tile.y == tile->tile.y+tile->tile.height) { - if(is_between_strict(it->tile.x,it->tile.x+it->tile.width,center)||it->tile.x+it->tile.width==center) { + if(it->tile.y == tile->tile.y + tile->tile.height) { + if(is_between_strict(it->tile.x, it->tile.x + it->tile.width, + center) || + it->tile.x + it->tile.width == center) { return it; } } @@ -223,11 +231,11 @@ swap_tile(struct cg_tile *tile, view_maximize(swap_tile->view, swap_tile); } seat_set_focus(server->seat, swap_tile->view); - ipc_send_event( - tile->workspace->output->server, - "{\"event_name\":\"swap_tile\",\"tile_id\":\"%d\",\"swap_tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", - tile->id, swap_tile->id, tile->workspace->num + 1, - tile->workspace->output->wlr_output->name); + ipc_send_event(tile->workspace->output->server, + "{\"event_name\":\"swap_tile\",\"tile_id\":\"%d\",\"swap_" + "tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", + tile->id, swap_tile->id, tile->workspace->num + 1, + tile->workspace->output->wlr_output->name); } void @@ -372,7 +380,9 @@ resize(struct cg_tile *tile, const struct cg_tile *parent, int coord_offset, view_maximize(tile->view, tile); } ipc_send_event(tile->workspace->output->server, - "{\"event_name\":\"resize_tile\",\"tile_id\":\"%d\",\"old_dims\":\"[%d;%d;%d;%d]\",\"new_dims\":\"[%d;%d;%d;%d]\",\"workspace\":\"%d\",\"output\":\"%s\"}", + "{\"event_name\":\"resize_tile\",\"tile_id\":\"%d\",\"old_" + "dims\":\"[%d;%d;%d;%d]\",\"new_dims\":\"[%d;%d;%d;%d]\"," + "\"workspace\":\"%d\",\"output\":\"%s\"}", tile->id, old_x, old_y, old_height, old_width, tile->tile.x, tile->tile.y, tile->tile.height, tile->tile.width, tile->workspace->num + 1, @@ -466,38 +476,9 @@ resize_tile(struct cg_server *server, int hpixs, int vpixs) { void keybinding_workspace_fullscreen(struct cg_server *server) { - struct cg_view *current_view = seat_get_focus(server->seat); + output_make_workspace_fullscreen(server->curr_output,server->curr_output->curr_workspace); struct cg_output *output = server->curr_output; - - /* We are focused on the background */ - if(current_view == NULL) { - struct cg_view *it = NULL; - wl_list_for_each(it, &output->workspaces[output->curr_workspace]->views, - link) { - if(view_is_visible(it)) { - current_view = it; - break; - } - } - } - - workspace_free_tiles(output->workspaces[output->curr_workspace]); - if(full_screen_workspace_tiles(server->output_layout, output->wlr_output, - output->workspaces[output->curr_workspace], - &server->tiles_curr_id) != 0) { - wlr_log(WLR_ERROR, "Failed to allocate space for fullscreen workspace"); - 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); - ipc_send_event(output->server, + ipc_send_event(server, "{\"event_name\":\"fullscreen\",\"tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", output->workspaces[output->curr_workspace]->focused_tile->id, output->workspaces[output->curr_workspace]->num + 1, @@ -592,7 +573,8 @@ keybinding_split_output(struct cg_output *output, bool vertical) { } ipc_send_event( output->server, - "{\"event_name\":\"split\",\"tile_id\":\"%d\",\"new_tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\",\"vertical\":\"%d\"}", + "{\"event_name\":\"split\",\"tile_id\":\"%d\",\"new_tile_id\":\"%d\"," + "\"workspace\":\"%d\",\"output\":\"%s\",\"vertical\":\"%d\"}", curr_workspace->focused_tile->id, new_tile->id, curr_workspace->num + 1, curr_workspace->output->wlr_output->name, vertical); } @@ -608,7 +590,8 @@ keybinding_close_view(struct cg_view *view) { uint32_t ws = view->workspace->num; view->impl->close(view); ipc_send_event(outp->server, - "{\"event_name\":\"close\",\"view_id\":\"%d\",\"tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", + "{\"event_name\":\"close\",\"view_id\":\"%d\",\"tile_id\":" + "\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", view_id, tile_id, ws + 1, outp->wlr_output->name); } @@ -657,9 +640,11 @@ keybinding_cycle_outputs(struct cg_server *server, bool reverse) { } } set_output(server, output); - ipc_send_event( - output->server, "{\"event_name\":\"cycle_outputs\",\"old_output\":\"%s\",\"new_output\":\"%s\",\"reverse\":\"%d\"}", - old_output->wlr_output->name, output->wlr_output->name, reverse); + ipc_send_event(output->server, + "{\"event_name\":\"cycle_outputs\",\"old_output\":\"%s\"," + "\"new_output\":\"%s\",\"reverse\":\"%d\"}", + old_output->wlr_output->name, output->wlr_output->name, + reverse); } /* Cycle through views, whereby the workspace does not change */ @@ -702,11 +687,16 @@ keybinding_cycle_views(struct cg_server *server, bool reverse, bool ipc) { next_view->link.prev, curr_workspace->focused_tile->view, link); seat_set_focus(server->seat, next_view); if(ipc) { - ipc_send_event(curr_workspace->output->server, - "{\"event_name\":\"cycle_views\",\"old_view_id\":\"%d\",\"new_view_id\":\"%d\",\"tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", - current_view->link.next==curr_workspace->views.next?-1:(int) current_view->id, next_view==NULL?-1:(int) next_view->id, next_view->tile->id, - curr_workspace->num + 1, - curr_workspace->output->wlr_output->name); + ipc_send_event(curr_workspace->output->server, + "{\"event_name\":\"cycle_views\",\"old_view_id\":\"%d\"," + "\"new_view_id\":\"%d\",\"tile_id\":\"%d\"," + "\"workspace\":\"%d\",\"output\":\"%s\"}", + current_view->link.next == curr_workspace->views.next + ? -1 + : (int)current_view->id, + next_view == NULL ? -1 : (int)next_view->id, + next_view->tile->id, curr_workspace->num + 1, + curr_workspace->output->wlr_output->name); } } @@ -725,7 +715,8 @@ keybinding_cycle_tiles(struct cg_server *server, bool reverse) { seat_set_focus(server->seat, next_view); ipc_send_event( output->server, - "{\"event_name\":\"cycle_tiles\",\"old_tile_id\":\"%d\",\"new_tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", + "{\"event_name\":\"cycle_tiles\",\"old_tile_id\":\"%d\",\"new_tile_" + "id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\"}", old_tile->id, workspace->focused_tile->id, workspace->num + 1, output->wlr_output->name); } @@ -740,12 +731,13 @@ keybinding_switch_ws(struct cg_server *server, uint32_t ws) { } struct cg_output *output = server->curr_output; uint32_t old_ws = server->curr_output->curr_workspace; - workspace_focus(output,ws); + workspace_focus(output, ws); seat_set_focus(server->seat, server->curr_output->workspaces[ws]->focused_tile->view); message_printf(server->curr_output, "Workspace %d", ws + 1); ipc_send_event(output->server, - "{\"event_name\":\"switch_ws\",\"old_workspace\":\"%d\",\"new_workspace\":\"%d\",\"output\":\"%s\"}", + "{\"event_name\":\"switch_ws\",\"old_workspace\":\"%d\"," + "\"new_workspace\":\"%d\",\"output\":\"%s\"}", old_ws + 1, ws + 1, output->wlr_output->name); return 0; } @@ -770,17 +762,19 @@ struct dyn_str { char **str_arr; }; -/*Note that inp is in an invalid state after calling the function * and should no longer be used.*/ -char *dyn_str_to_str(struct dyn_str *inp) { - char *outp=calloc(inp->len+1,sizeof(char)); +/*Note that inp is in an invalid state after calling the function * and should + * no longer be used.*/ +char * +dyn_str_to_str(struct dyn_str *inp) { + char *outp = calloc(inp->len + 1, sizeof(char)); if(outp == NULL) { return NULL; } - outp[inp->len]='\0'; - uint32_t tmp_pos=0; - for(uint32_t i=0;icur_pos;++i) { - strcat(outp+tmp_pos,inp->str_arr[i]); - tmp_pos+=strlen(inp->str_arr[i]); + outp[inp->len] = '\0'; + uint32_t tmp_pos = 0; + for(uint32_t i = 0; i < inp->cur_pos; ++i) { + strcat(outp + tmp_pos, inp->str_arr[i]); + tmp_pos += strlen(inp->str_arr[i]); free(inp->str_arr[i]); } free(inp->str_arr); @@ -795,89 +789,98 @@ print_str(struct dyn_str *outp, const char *fmt, ...) { if(ret == NULL) { return -1; } - outp->str_arr[outp->cur_pos]=ret; + outp->str_arr[outp->cur_pos] = ret; ++outp->cur_pos; - outp->len+=strlen(ret); + outp->len += strlen(ret); return 0; } void -print_modes(struct dyn_str *str,char **modes) { - uint32_t len=0; - char **tmp=modes; - uint32_t nmemb=0; - while(*tmp!=NULL) { - len+=strlen(*tmp); +print_modes(struct dyn_str *str, char **modes) { + uint32_t len = 0; + char **tmp = modes; + uint32_t nmemb = 0; + while(*tmp != NULL) { + len += strlen(*tmp); ++nmemb; ++tmp; } - /* We are assuming here that we have at least one mode, which is given by the initialization of cagebreak */ - char *modes_str=calloc(len+3*(nmemb-1)+1, sizeof(char)); - modes_str[len+nmemb-1]='\0'; - uint32_t tmp_pos=0; - for(uint32_t i=0;iid); - char *title_str=view->impl->get_title(view); - print_str(&outp_str,"\"title\": \"%s\",\n",title_str==NULL?"":title_str); - print_str(&outp_str,"\"coords\": [\"x\":%d,\"y\":%d],\n",view->ox,view->oy); + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t nmemb = 4; + outp_str.str_arr = calloc(nmemb, sizeof(char *)); + print_str(&outp_str, "\"id\": %d,\n", view->id); + char *title_str = view->impl->get_title(view); + print_str(&outp_str, "\"title\": \"%s\",\n", + title_str == NULL ? "" : title_str); + print_str(&outp_str, "\"coords\": [\"x\":%d,\"y\":%d],\n", view->ox, + view->oy); #if CG_HAS_XWAYLAND - print_str(&outp_str,"\"type\": \"%s\",\n",view->type==CG_XWAYLAND_VIEW?"xwayland":"xdg"); + print_str(&outp_str, "\"type\": \"%s\",\n", + view->type == CG_XWAYLAND_VIEW ? "xwayland" : "xdg"); #else - print_str(&outp_str,"\"type\": \"xdg\",\n"); + print_str(&outp_str, "\"type\": \"xdg\",\n"); #endif return dyn_str_to_str(&outp_str); } -char *print_tile(struct cg_tile *tile) { +char * +print_tile(struct cg_tile *tile) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - uint32_t nmemb=4; - outp_str.str_arr=calloc(nmemb,sizeof(char *)); - print_str(&outp_str,"\"id\": %d,\n",tile->id); - print_str(&outp_str,"\"coords\": [\"x\":%d,\"y\":%d],\n",tile->tile.x,tile->tile.y); - print_str(&outp_str,"\"size\": [\"width\":%d,\"height\":%d],\n",tile->tile.width,tile->tile.height); - print_str(&outp_str,"\"view\": \"%d\",\n",tile->view==NULL?-1:(int)tile->view->id); + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t nmemb = 4; + outp_str.str_arr = calloc(nmemb, sizeof(char *)); + print_str(&outp_str, "\"id\": %d,\n", tile->id); + print_str(&outp_str, "\"coords\": [\"x\":%d,\"y\":%d],\n", tile->tile.x, + tile->tile.y); + print_str(&outp_str, "\"size\": [\"width\":%d,\"height\":%d],\n", + tile->tile.width, tile->tile.height); + print_str(&outp_str, "\"view\": \"%d\",\n", + tile->view == NULL ? -1 : (int)tile->view->id); return dyn_str_to_str(&outp_str); } char * print_views(struct cg_workspace *ws) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - uint32_t nviews=wl_list_length(&ws->views); - if(nviews==0) { + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t nviews = wl_list_length(&ws->views); + if(nviews == 0) { return strdup("{}"); } - outp_str.str_arr=calloc(2*nviews-1,sizeof(char *)); + outp_str.str_arr = calloc(2 * nviews - 1, sizeof(char *)); struct cg_view *it; - uint32_t count=0; - wl_list_for_each(it,&ws->views,link) { - if(count!=0) { - print_str(&outp_str,","); + uint32_t count = 0; + wl_list_for_each(it, &ws->views, link) { + if(count != 0) { + print_str(&outp_str, ","); } ++count; - char *view_str=print_view(it); - if(view_str!=NULL) { - print_str(&outp_str,"{\n%s\n}",view_str); + char *view_str = print_view(it); + if(view_str != NULL) { + print_str(&outp_str, "{\n%s\n}", view_str); free(view_str); } } @@ -887,27 +890,29 @@ print_views(struct cg_workspace *ws) { char * print_tiles(struct cg_workspace *ws) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - uint32_t ntiles=0; - bool first=true; - for(struct cg_tile *tile=ws->focused_tile;first||tile!=ws->focused_tile;tile=tile->next) { - first=false; + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t ntiles = 0; + bool first = true; + for(struct cg_tile *tile = ws->focused_tile; + first || tile != ws->focused_tile; tile = tile->next) { + first = false; ++ntiles; } - if(ntiles==0) { + if(ntiles == 0) { return strdup("{}"); } - outp_str.str_arr=calloc(2*ntiles-1,sizeof(char *)); - first=true; - for(struct cg_tile *tile=ws->focused_tile;first||tile!=ws->focused_tile;tile=tile->next) { - if(first==false) { - print_str(&outp_str,","); + outp_str.str_arr = calloc(2 * ntiles - 1, sizeof(char *)); + first = true; + for(struct cg_tile *tile = ws->focused_tile; + first || tile != ws->focused_tile; tile = tile->next) { + if(first == false) { + print_str(&outp_str, ","); } - first=false; - char *tile_str=print_tile(tile); - if(tile_str!=NULL) { - print_str(&outp_str,"{\n%s\n}",tile_str); + first = false; + char *tile_str = print_tile(tile); + if(tile_str != NULL) { + print_str(&outp_str, "{\n%s\n}", tile_str); free(tile_str); } } @@ -917,41 +922,41 @@ print_tiles(struct cg_workspace *ws) { char * print_workspace(struct cg_workspace *ws) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - uint32_t nmemb=6; - outp_str.str_arr=calloc(nmemb,sizeof(char *)); - print_str(&outp_str,"\"views\": ["); - char *views_str=print_views(ws); - if(views_str!=NULL) { - print_str(&outp_str,"%s",views_str); + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t nmemb = 6; + outp_str.str_arr = calloc(nmemb, sizeof(char *)); + print_str(&outp_str, "\"views\": ["); + char *views_str = print_views(ws); + if(views_str != NULL) { + print_str(&outp_str, "%s", views_str); free(views_str); } - print_str(&outp_str,"],"); - print_str(&outp_str,"\"tiles\": ["); - char *tiles_str=print_tiles(ws); - if(tiles_str!=NULL) { - print_str(&outp_str,"%s",tiles_str); + print_str(&outp_str, "],"); + print_str(&outp_str, "\"tiles\": ["); + char *tiles_str = print_tiles(ws); + if(tiles_str != NULL) { + print_str(&outp_str, "%s", tiles_str); free(tiles_str); } - print_str(&outp_str,"]"); + print_str(&outp_str, "]"); return dyn_str_to_str(&outp_str); } char * print_workspaces(struct cg_output *outp) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - outp_str.str_arr=calloc((2*outp->server->nws-1)+2,sizeof(char *)); + outp_str.len = 0; + outp_str.cur_pos = 0; + outp_str.str_arr = calloc((2 * outp->server->nws - 1) + 2, sizeof(char *)); print_str(&outp_str, "\"workspaces\": ["); - for(int i=0;iserver->nws;++i) { - if(i!=0) { - print_str(&outp_str,","); + for(int i = 0; i < outp->server->nws; ++i) { + if(i != 0) { + print_str(&outp_str, ","); } - char *ws=print_workspace(outp->workspaces[i]); + char *ws = print_workspace(outp->workspaces[i]); if(ws != NULL) { - print_str(&outp_str,"{%s}",ws); + print_str(&outp_str, "{%s}", ws); free(ws); } } @@ -962,42 +967,42 @@ print_workspaces(struct cg_output *outp) { char * print_output(struct cg_output *outp) { struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - uint32_t nmemb=5; - outp_str.str_arr=calloc(nmemb,sizeof(char *)); - print_str(&outp_str,"\"%s\": {\n",outp->wlr_output->name); - print_str(&outp_str,"\"priority\": %d,\n",outp->priority); - print_str(&outp_str,"\"curr_workspace\": %d,\n",outp->curr_workspace); - char *workspaces_str=print_workspaces(outp); - if(workspaces_str!=NULL) { - print_str(&outp_str, "%s",workspaces_str); + outp_str.len = 0; + outp_str.cur_pos = 0; + uint32_t nmemb = 5; + outp_str.str_arr = calloc(nmemb, sizeof(char *)); + print_str(&outp_str, "\"%s\": {\n", outp->wlr_output->name); + print_str(&outp_str, "\"priority\": %d,\n", outp->priority); + print_str(&outp_str, "\"curr_workspace\": %d,\n", outp->curr_workspace); + char *workspaces_str = print_workspaces(outp); + if(workspaces_str != NULL) { + print_str(&outp_str, "%s", workspaces_str); free(workspaces_str); } - print_str(&outp_str,"}"); + print_str(&outp_str, "}"); return dyn_str_to_str(&outp_str); } char * print_outputs(struct cg_server *server) { - uint32_t noutps=wl_list_length(&server->outputs); + uint32_t noutps = wl_list_length(&server->outputs); struct dyn_str outp_str; - outp_str.len=0; - outp_str.cur_pos=0; - outp_str.str_arr=calloc((2*noutps-1)+2,sizeof(char *)); + outp_str.len = 0; + outp_str.cur_pos = 0; + outp_str.str_arr = calloc((2 * noutps - 1) + 2, sizeof(char *)); print_str(&outp_str, "\"outputs\": ["); struct cg_output *it; - uint32_t count=0; - wl_list_for_each(it,&server->outputs,link) { - if(count!=0) { - print_str(&outp_str,","); + uint32_t count = 0; + wl_list_for_each(it, &server->outputs, link) { + if(count != 0) { + print_str(&outp_str, ","); } ++count; - char *outp=print_output(it); + char *outp = print_output(it); if(outp == NULL) { continue; } - print_str(&outp_str,"%s",outp); + print_str(&outp_str, "%s", outp); free(outp); } print_str(&outp_str, "],\n"); @@ -1007,26 +1012,29 @@ print_outputs(struct cg_server *server) { void keybinding_dump(struct cg_server *server) { struct dyn_str str; - str.len=0; - str.cur_pos=0; - uint32_t nmemb=10; - str.str_arr=calloc(nmemb,sizeof(char *)); + str.len = 0; + str.cur_pos = 0; + uint32_t nmemb = 10; + str.str_arr = calloc(nmemb, sizeof(char *)); - print_str(&str,"{"); - print_str(&str,"\"nws\":%d,\n",server->nws); - print_str(&str,"\"bg_color\":[%f,%f,%f,%f],\n",server->bg_color[0],server->bg_color[1],server->bg_color[2],server->bg_color[3]); - print_str(&str,"\"views_curr_id\":%d,\n",server->views_curr_id); - print_str(&str,"\"tiles_curr_id\":%d,\n",server->tiles_curr_id); - print_str(&str,"\"curr_output\":%s,\n",server->curr_output->wlr_output->name); - print_modes(&str,server->modes); - char *outps_str=print_outputs(server); - print_str(&str,"%s",outps_str); + print_str(&str, "{"); + print_str(&str, "\"nws\":%d,\n", server->nws); + print_str(&str, "\"bg_color\":[%f,%f,%f,%f],\n", server->bg_color[0], + server->bg_color[1], server->bg_color[2], server->bg_color[3]); + print_str(&str, "\"views_curr_id\":%d,\n", server->views_curr_id); + print_str(&str, "\"tiles_curr_id\":%d,\n", server->tiles_curr_id); + print_str(&str, "\"curr_output\":%s,\n", + server->curr_output->wlr_output->name); + print_modes(&str, server->modes); + char *outps_str = print_outputs(server); + print_str(&str, "%s", outps_str); free(outps_str); - print_str(&str,"\"cursor_coords\":{\"x\":%f,\"y\":%f},\n",server->seat->cursor->x,server->seat->cursor->y); - print_str(&str,"}"); + print_str(&str, "\"cursor_coords\":{\"x\":%f,\"y\":%f},\n", + server->seat->cursor->x, server->seat->cursor->y); + print_str(&str, "}"); - char *send_str=dyn_str_to_str(&str); - if(send_str==NULL) { + char *send_str = dyn_str_to_str(&str); + if(send_str == NULL) { wlr_log(WLR_ERROR, "Unable to create output string for \"dump\"."); } ipc_send_event(server, send_str); @@ -1063,7 +1071,7 @@ keybinding_move_view_to_cycle_output(struct cg_server *server, bool reverse) { wl_list_remove(&view->link); server->curr_output->workspaces[server->curr_output->curr_workspace] ->focused_tile->view = NULL; - keybinding_cycle_views(server, false,false); + keybinding_cycle_views(server, false, false); if(server->curr_output->workspaces[server->curr_output->curr_workspace] ->focused_tile->view == NULL) { seat_set_focus(server->seat, NULL); @@ -1071,7 +1079,9 @@ keybinding_move_view_to_cycle_output(struct cg_server *server, bool reverse) { } keybinding_cycle_outputs(server, reverse); if(view != NULL) { - struct cg_workspace *ws=server->curr_output->workspaces[server->curr_output->curr_workspace]; + struct cg_workspace *ws = + server->curr_output + ->workspaces[server->curr_output->curr_workspace]; wl_list_insert(&ws->views, &view->link); ws->focused_tile->view = view; wlr_scene_node_reparent(view->scene_node, &ws->scene->node); @@ -1080,11 +1090,11 @@ keybinding_move_view_to_cycle_output(struct cg_server *server, bool reverse) { view_maximize(view, view->tile); seat_set_focus(server->seat, view); } - ipc_send_event( - server, - "{\"event_name\":\"move_view_cycle_output\",\"view_id\":\"%d\",\"old_output\":\"%s\",\"new_output\":\"%s\"}", - view->id, old_outp->wlr_output->name, - server->curr_output->wlr_output->name); + ipc_send_event(server, + "{\"event_name\":\"move_view_cycle_output\",\"view_id\":\"%" + "d\",\"old_output\":\"%s\",\"new_output\":\"%s\"}", + view->id, old_outp->wlr_output->name, + server->curr_output->wlr_output->name); } void @@ -1130,7 +1140,7 @@ keybinding_set_nws(struct cg_server *server, int nws) { } if(output->curr_workspace >= nws) { - workspace_focus(output,nws-1); + workspace_focus(output, nws - 1); } } server->nws = nws; @@ -1138,8 +1148,10 @@ keybinding_set_nws(struct cg_server *server, int nws) { server->seat, server->curr_output->workspaces[server->curr_output->curr_workspace] ->focused_tile->view); - ipc_send_event(server, "{\"event_name\":\"set_nws\",\"old_nws\":\"%d\",\"new_nws\":\"%d\"}", old_nws, - server->nws); + ipc_send_event( + server, + "{\"event_name\":\"set_nws\",\"old_nws\":\"%d\",\"new_nws\":\"%d\"}", + old_nws, server->nws); } void @@ -1156,29 +1168,34 @@ keybinding_definemode(struct cg_server *server, char *mode) { server->modes[length] = NULL; server->modes[length - 1] = strdup(mode); - ipc_send_event(server, "{\"event_name\":\"definemode\",\"mode\":\"%s\"}", mode); + ipc_send_event(server, "{\"event_name\":\"definemode\",\"mode\":\"%s\"}", + mode); } void keybinding_definekey(struct cg_server *server, struct keybinding *kb) { keybinding_list_push(server->keybindings, kb); - ipc_send_event(server, "{\"event_name\":\"definekey\",\"modifiers\":\"%d\",\"key\":\"%d\",\"command\":\"%d\"}", + ipc_send_event(server, + "{\"event_name\":\"definekey\",\"modifiers\":\"%d\",\"key\":" + "\"%d\",\"command\":\"%d\"}", kb->modifiers, kb->key, kb->action); } void keybinding_set_background(struct cg_server *server, float *bg) { - ipc_send_event(server, "{\"event_name\":\"background\",\"old_bg\":\"[%f,%f,%f]\",\"new_bg\":\"[%f,%f,%f]\"}", + ipc_send_event(server, + "{\"event_name\":\"background\",\"old_bg\":\"[%f,%f,%f]\"," + "\"new_bg\":\"[%f,%f,%f]\"}", server->bg_color[0], server->bg_color[1], server->bg_color[2], bg[0], bg[1], bg[2]); server->bg_color[0] = bg[0]; server->bg_color[1] = bg[1]; server->bg_color[2] = bg[2]; - struct cg_output *it=NULL; - wl_list_for_each(it,&server->outputs,link) { + struct cg_output *it = NULL; + wl_list_for_each(it, &server->outputs, link) { wlr_scene_rect_set_color(it->bg, server->bg_color); } - wl_list_for_each(it,&server->disabled_outputs,link) { + wl_list_for_each(it, &server->disabled_outputs, link) { wlr_scene_rect_set_color(it->bg, server->bg_color); } } @@ -1191,7 +1208,9 @@ keybinding_switch_output(struct cg_server *server, int output) { wl_list_for_each(it, &server->outputs, link) { if(count == output) { set_output(server, it); - ipc_send_event(server, "{\"event_name\":\"switch_output\",\"old_output\":\"%s\",\"new_output\":\"%s\"}", + ipc_send_event(server, + "{\"event_name\":\"switch_output\",\"old_output\":" + "\"%s\",\"new_output\":\"%s\"}", old_outp->wlr_output->name, it->wlr_output->name); return; } @@ -1211,7 +1230,7 @@ keybinding_move_view_to_output(struct cg_server *server, int output_num) { wl_list_remove(&view->link); server->curr_output->workspaces[server->curr_output->curr_workspace] ->focused_tile->view = NULL; - keybinding_cycle_views(server, false,false); + keybinding_cycle_views(server, false, false); if(server->curr_output->workspaces[server->curr_output->curr_workspace] ->focused_tile->view == NULL) { seat_set_focus(server->seat, NULL); @@ -1235,10 +1254,12 @@ keybinding_move_view_to_output(struct cg_server *server, int output_num) { view_title = view->impl->get_title(view); view_id = view->id; } - ipc_send_event(server, - "{\"event_name\":\"move_view_to_output\",\"view_id\":\"%d\",\"old_output\":\"%s\",\"new_output\":\"%s\",\"view_title\":\"%s\"}", - view_id, old_outp->wlr_output->name, - server->curr_output->wlr_output->name, view_title); + ipc_send_event( + server, + "{\"event_name\":\"move_view_to_output\",\"view_id\":\"%d\",\"old_" + "output\":\"%s\",\"new_output\":\"%s\",\"view_title\":\"%s\"}", + view_id, old_outp->wlr_output->name, + server->curr_output->wlr_output->name, view_title); } void @@ -1270,10 +1291,12 @@ keybinding_move_view_to_workspace(struct cg_server *server, uint32_t ws) { seat_set_focus(server->seat, view); } ipc_send_event(server, - "{\"event_name\":\"move_view_to_ws\",\"view_id\":\"%d\",\"old_workspace\":\"%d\",\"new_workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", - view==NULL?-1:(int)view->id, old_ws, ws, + "{\"event_name\":\"move_view_to_ws\",\"view_id\":\"%d\"," + "\"old_workspace\":\"%d\",\"new_workspace\":\"%d\"," + "\"output\":\"%s\",\"view_title\":\"%s\"}", + view == NULL ? -1 : (int)view->id, old_ws, ws, server->curr_output->wlr_output->name, - view==NULL?"":view->impl->get_title(view)); + view == NULL ? "" : view->impl->get_title(view)); } void @@ -1322,16 +1345,20 @@ keybinding_configure_output(struct cg_server *server, wl_list_for_each_safe(output, tmp_output, &server->outputs, link) { if(strcmp(config->output_name, output->wlr_output->name) == 0) { output_configure(server, output); - ipc_send_event(output->server, "{\"event_name\":\"configure_output\",\"output\":\"%s\"}", - cfg->output_name); + ipc_send_event( + output->server, + "{\"event_name\":\"configure_output\",\"output\":\"%s\"}", + cfg->output_name); return; } } wl_list_for_each_safe(output, tmp_output, &server->disabled_outputs, link) { if(strcmp(config->output_name, output->wlr_output->name) == 0) { output_configure(server, output); - ipc_send_event(output->server, "{\"event_name\":\"configure_output\",\"output\":\"%s\"}", - cfg->output_name); + ipc_send_event( + output->server, + "{\"event_name\":\"configure_output\",\"output\":\"%s\"}", + cfg->output_name); return; } } @@ -1341,7 +1368,9 @@ void keybinding_configure_input(struct cg_server *server, struct cg_input_config *cfg) { cg_input_apply_config(cfg, server); - ipc_send_event(server, "{\"event_name\":\"configure_input\",\"input\":\"%s\"}", cfg->identifier); + ipc_send_event(server, + "{\"event_name\":\"configure_input\",\"input\":\"%s\"}", + cfg->identifier); } void @@ -1392,21 +1421,19 @@ run_action(enum keybinding_action action, struct cg_server *server, case KEYBINDING_SPLIT_VERTICAL: keybinding_split_vertical(server); break; - case KEYBINDING_RUN_COMMAND: - { - int pid; - if((pid=fork()) == 0) { - if(fork() == 0) { - into_process(data.c); - } - _exit(0); - } else if(pid > 0) { - waitpid(pid,NULL,0); + case KEYBINDING_RUN_COMMAND: { + int pid; + if((pid = fork()) == 0) { + if(fork() == 0) { + into_process(data.c); } + _exit(0); + } else if(pid > 0) { + waitpid(pid, NULL, 0); } - break; + } break; case KEYBINDING_CYCLE_VIEWS: - keybinding_cycle_views(server, data.b,true); + keybinding_cycle_views(server, data.b, true); break; case KEYBINDING_CYCLE_TILES: keybinding_cycle_tiles(server, data.b); @@ -1424,7 +1451,9 @@ run_action(enum keybinding_action action, struct cg_server *server, server->seat->mode = data.u; break; case KEYBINDING_SWITCH_DEFAULT_MODE: - ipc_send_event(server, "{\"event_name\":\"switch_default_mode\",\"old_mode\":\"%d\",\"mode\":\"%d\"}", + ipc_send_event(server, + "{\"event_name\":\"switch_default_mode\",\"old_mode\":" + "\"%d\",\"mode\":\"%d\"}", server->seat->default_mode, data.u); server->seat->mode = data.u; server->seat->default_mode = data.u; @@ -1441,7 +1470,7 @@ run_action(enum keybinding_action action, struct cg_server *server, keybinding_show_info(server); break; case KEYBINDING_DISPLAY_MESSAGE: - keybinding_display_message(server,data.c); + keybinding_display_message(server, data.c); break; case KEYBINDING_RESIZE_TILE_HORIZONTAL: resize_tile(server, data.i, 0); diff --git a/message.c b/message.c index 8e8e0d1..cbafb1c 100644 --- a/message.c +++ b/message.c @@ -1,17 +1,17 @@ #include #include #include +#include #include #include #include +#include +#include #include #include #include -#include -#include -#include #include -#include +#include #include "message.h" #include "output.h" @@ -26,14 +26,17 @@ struct msg_buffer { size_t stride; }; -static void msg_buffer_destroy(struct wlr_buffer *wlr_buffer) { +static void +msg_buffer_destroy(struct wlr_buffer *wlr_buffer) { struct msg_buffer *buffer = wl_container_of(wlr_buffer, buffer, base); free(buffer->data); free(buffer); } -static bool msg_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer, - uint32_t flags, void **data, uint32_t *format, size_t *stride) { +static bool +msg_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer, uint32_t flags, + void **data, uint32_t *format, + size_t *stride) { struct msg_buffer *buffer = wl_container_of(wlr_buffer, buffer, base); if(data != NULL) { *data = (void *)buffer->data; @@ -47,19 +50,21 @@ static bool msg_buffer_begin_data_ptr_access(struct wlr_buffer *wlr_buffer, return true; } -static void msg_buffer_end_data_ptr_access(struct wlr_buffer *wlr_buffer) { +static void +msg_buffer_end_data_ptr_access(struct wlr_buffer *wlr_buffer) { // This space is intentionally left blank } static const struct wlr_buffer_impl msg_buffer_impl = { - .destroy = msg_buffer_destroy, - .begin_data_ptr_access = msg_buffer_begin_data_ptr_access, - .end_data_ptr_access = msg_buffer_end_data_ptr_access, + .destroy = msg_buffer_destroy, + .begin_data_ptr_access = msg_buffer_begin_data_ptr_access, + .end_data_ptr_access = msg_buffer_end_data_ptr_access, }; -static struct msg_buffer *msg_buffer_create(uint32_t width, uint32_t height, uint32_t stride) { +static struct msg_buffer * +msg_buffer_create(uint32_t width, uint32_t height, uint32_t stride) { struct msg_buffer *buffer = calloc(1, sizeof(*buffer)); - if (buffer == NULL) { + if(buffer == NULL) { return NULL; } @@ -68,7 +73,7 @@ static struct msg_buffer *msg_buffer_create(uint32_t width, uint32_t height, uin buffer->stride = stride; buffer->data = malloc(buffer->stride * height); - if (buffer->data == NULL) { + if(buffer->data == NULL) { free(buffer); return NULL; } @@ -150,14 +155,16 @@ create_message_texture(const char *string, const struct cg_output *output) { unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); - struct msg_buffer *buf=msg_buffer_create(width, height,stride); + struct msg_buffer *buf = msg_buffer_create(width, height, stride); void *data_ptr; - if(!wlr_buffer_begin_data_ptr_access(&buf->base, WLR_BUFFER_DATA_PTR_ACCESS_WRITE,&data_ptr,NULL,NULL)) { + if(!wlr_buffer_begin_data_ptr_access(&buf->base, + WLR_BUFFER_DATA_PTR_ACCESS_WRITE, + &data_ptr, NULL, NULL)) { wlr_log(WLR_ERROR, "Failed to get pointer access to message buffer"); return NULL; } - memcpy(data_ptr,data,stride*height); + memcpy(data_ptr, data, stride * height); wlr_buffer_end_data_ptr_access(&buf->base); cairo_surface_destroy(surface); @@ -217,12 +224,18 @@ message_set_output(struct cg_output *output, const char *string, break; } - message->message=wlr_scene_buffer_create(&output->scene_output->scene->node,&buf->base); + struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(output->server->scene,output->wlr_output); + if(scene_output == NULL) { + return; + } + message->message=wlr_scene_buffer_create(&scene_output->scene->node,&buf->base); wlr_scene_node_raise_to_top(&message->message->node); - wlr_scene_node_set_enabled(&message->message->node,true); + wlr_scene_node_set_enabled(&message->message->node, true); struct wlr_box *outp_box = wlr_output_layout_get_box( output->server->output_layout, output->wlr_output); - wlr_scene_node_set_position(&message->message->node, message->position->x+outp_box->x, message->position->y+outp_box->y); + wlr_scene_node_set_position(&message->message->node, + message->position->x + outp_box->x, + message->position->y + outp_box->y); } void @@ -279,7 +292,7 @@ message_clear(struct cg_output *output) { struct cg_message *message, *tmp; wl_list_for_each_safe(message, tmp, &output->messages, link) { wl_list_remove(&message->link); - struct wlr_buffer *buf=message->message->buffer; + struct wlr_buffer *buf = message->message->buffer; wlr_scene_node_destroy(&message->message->node); free(message->position); buf->impl->destroy(buf); diff --git a/output.c b/output.c index 66b644f..e815f90 100644 --- a/output.c +++ b/output.c @@ -25,9 +25,9 @@ #include #include #include +#include #include #include -#include #include #include #if CG_HAS_XWAYLAND @@ -71,24 +71,19 @@ output_clear(struct cg_output *output) { first = false; tile->view = NULL; } + struct cg_workspace *ws = + server->curr_output + ->workspaces[server->curr_output->curr_workspace]; wl_list_for_each_safe(view, view_tmp, &output->workspaces[i]->views, link) { wl_list_remove(&view->link); if(wl_list_empty(&server->outputs)) { view->impl->destroy(view); } else { - wl_list_insert( - &server->curr_output - ->workspaces[server->curr_output->curr_workspace] - ->views, - &view->link); - view->workspace = - server->curr_output - ->workspaces[server->curr_output->curr_workspace]; - view->tile = - server->curr_output - ->workspaces[server->curr_output->curr_workspace] - ->focused_tile; + wl_list_insert(&ws->views, &view->link); + wlr_scene_node_reparent(view->scene_node, &ws->scene->node); + view->workspace = ws; + view->tile = ws->focused_tile; if(server->seat->focused_view == NULL) { seat_set_focus(server->seat, view); } @@ -100,18 +95,10 @@ output_clear(struct cg_output *output) { if(wl_list_empty(&server->outputs)) { view->impl->destroy(view); } else { - wl_list_insert( - &server->curr_output - ->workspaces[server->curr_output->curr_workspace] - ->unmanaged_views, - &view->link); - view->workspace = - server->curr_output - ->workspaces[server->curr_output->curr_workspace]; - view->tile = - server->curr_output - ->workspaces[server->curr_output->curr_workspace] - ->focused_tile; + wl_list_insert(&ws->unmanaged_views, &view->link); + wlr_scene_node_reparent(view->scene_node, &ws->scene->node); + view->workspace = ws; + view->tile = ws->focused_tile; } } } @@ -141,7 +128,9 @@ output_destroy(struct cg_output *output) { free(output); if(outp_name != NULL) { - ipc_send_event(server, "{\"event_name\":\"new_output\",\"output\":\"%s\"}", outp_name); + ipc_send_event(server, + "{\"event_name\":\"new_output\",\"output\":\"%s\"}", + outp_name); free(outp_name); } else { wlr_log(WLR_ERROR, @@ -160,15 +149,19 @@ handle_output_destroy(struct wl_listener *listener, void *data) { static void handle_output_frame(struct wl_listener *listener, void *data) { - struct cg_output *output=wl_container_of(listener, output, frame); + struct cg_output *output = wl_container_of(listener, output, frame); if(!output->wlr_output->enabled) { return; } - wlr_scene_output_commit(output->scene_output); + struct wlr_scene_output *scene_output=wlr_scene_get_scene_output(output->server->scene,output->wlr_output); + if(scene_output == NULL) { + return; + } + wlr_scene_output_commit(scene_output); - struct timespec now={0}; + struct timespec now = {0}; clock_gettime(CLOCK_MONOTONIC, &now); - wlr_scene_output_send_frame_done(output->scene_output, &now); + wlr_scene_output_send_frame_done(scene_output, &now); } struct cg_output_config * @@ -182,7 +175,7 @@ output_find_config(struct cg_server *server, struct wlr_output *output) { return NULL; } -static void +static int output_set_mode(struct wlr_output *output, int width, int height, float refresh_rate) { int mhz = (int)(refresh_rate * 1000); @@ -191,7 +184,7 @@ output_set_mode(struct wlr_output *output, int width, int height, wlr_log(WLR_DEBUG, "Assigning custom mode to %s", output->name); wlr_output_set_custom_mode(output, width, height, refresh_rate > 0 ? mhz : 0); - return; + return 0; } struct wlr_output_mode *mode, *best = NULL; @@ -215,19 +208,28 @@ output_set_mode(struct wlr_output *output, int width, int height, wlr_log(WLR_DEBUG, "Assigning configured mode to %s", output->name); } wlr_output_set_mode(output, best); + wlr_output_commit(output); if(!wlr_output_test(output)) { - wlr_log(WLR_ERROR, "Unable to assign configured mode to %s, picking arbitrary available mode",output->name); + wlr_log(WLR_ERROR, + "Unable to assign configured mode to %s, picking arbitrary " + "available mode", + output->name); struct wlr_output_mode *mode; wl_list_for_each(mode, &output->modes, link) { if(mode == best) { continue; } wlr_output_set_mode(output, mode); + wlr_output_commit(output); if(wlr_output_test(output)) { break; } } + if(!wlr_output_test(output)) { + return 1; + } } + return 0; } void @@ -285,32 +287,41 @@ output_configure(struct cg_server *server, struct cg_output *output) { wlr_output_enable(wlr_output, false); wlr_output_commit(wlr_output); } else { - wl_list_remove(&output->link); if(config->priority != -1) { output->priority = config->priority; } if(config->pos.x != -1) { - output_set_mode(wlr_output, config->pos.width, - config->pos.height, config->refresh_rate); + if(output_set_mode(wlr_output, config->pos.width, + config->pos.height, config->refresh_rate)!=0) { + wlr_log(WLR_ERROR,"Setting output mode failed, disabling output."); + output_clear(output); + wl_list_insert(&server->disabled_outputs,&output->link); + wlr_output_enable(wlr_output, false); + wlr_output_commit(wlr_output); + return; + } wlr_output_layout_add(server->output_layout, wlr_output, config->pos.x, config->pos.y); + /* Since the size of the output may have changed, we reinitialize all workspaces with a fullscreen layout */ + for(unsigned int i = 0; i < output->server->nws; ++i) { + output_make_workspace_fullscreen(output,i); + } } + wl_list_remove(&output->link); output_insert(server, output); wlr_output_enable(wlr_output, true); wlr_output_commit(wlr_output); } } - struct wlr_scene_output *scene_output; - wl_list_for_each(scene_output,&output->server->scene->outputs,link) { - if(scene_output->output == wlr_output) { - output->scene_output=scene_output; - break; - } - } if(output->bg!=NULL) { wlr_scene_node_destroy(&output->bg->node); + output->bg=NULL; } - output->bg=wlr_scene_rect_create(&output->scene_output->scene->node, output->wlr_output->width,output->wlr_output->height, server->bg_color); + struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(output->server->scene,output->wlr_output); + if(scene_output == NULL) { + return; + } + output->bg=wlr_scene_rect_create(&scene_output->scene->node, output->wlr_output->width,output->wlr_output->height, server->bg_color); struct wlr_box *box = wlr_output_layout_get_box( server->output_layout, output->wlr_output); wlr_scene_node_set_position(&output->bg->node, box->x, box->y); @@ -355,6 +366,42 @@ handle_output_mode(struct wl_listener *listener, void *data) { } } +void +output_make_workspace_fullscreen(struct cg_output *output,int ws) { + struct cg_server *server=output->server; + struct cg_view *current_view = seat_get_focus(server->seat); + + if(current_view == NULL||ws != output->curr_workspace) { + struct cg_view *it = NULL; + wl_list_for_each(it, &output->workspaces[ws]->views, + link) { + if(view_is_visible(it)) { + current_view = it; + break; + } + } + } + + workspace_free_tiles(output->workspaces[ws]); + if(full_screen_workspace_tiles(server->output_layout, output->wlr_output, + output->workspaces[ws], + &server->tiles_curr_id) != 0) { + wlr_log(WLR_ERROR, "Failed to allocate space for fullscreen workspace"); + return; + } + + struct cg_view *it_view; + wl_list_for_each(it_view, &output->workspaces[ws]->views, link) { + it_view->tile = output->workspaces[ws]->focused_tile; + } + + if(ws == output->curr_workspace) { + seat_set_focus(server->seat, current_view); + } +} + + + #if CG_HAS_FANALYZE #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak" @@ -364,7 +411,8 @@ handle_new_output(struct wl_listener *listener, void *data) { struct cg_server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; - if(!wlr_output_init_render(wlr_output,server->allocator,server->renderer)) { + if(!wlr_output_init_render(wlr_output, server->allocator, + server->renderer)) { wlr_log(WLR_ERROR, "Failed to initialize output rendering"); return; } @@ -415,7 +463,7 @@ handle_new_output(struct wl_listener *listener, void *data) { } wlr_scene_node_raise_to_top(&output->workspaces[0]->scene->node); - workspace_focus(output,0); + workspace_focus(output, 0); /* We are the first output. Set the current output to this one. */ if(server->curr_output == NULL) { @@ -433,8 +481,10 @@ handle_new_output(struct wl_listener *listener, void *data) { wl_signal_add(&wlr_output->events.commit, &output->commit); output->mode.notify = handle_output_mode; wl_signal_add(&wlr_output->events.mode, &output->mode); - ipc_send_event(server, "{\"event_name\":\"new_output\",\"output\":\"%s\",\"priority\":\"%d\"}", - output->wlr_output->name, output->priority); + ipc_send_event( + server, + "{\"event_name\":\"new_output\",\"output\":\"%s\",\"priority\":\"%d\"}", + output->wlr_output->name, output->priority); } #if CG_HAS_FANALYZE #pragma GCC diagnostic pop diff --git a/output.h b/output.h index 787efdd..492700a 100644 --- a/output.h +++ b/output.h @@ -12,7 +12,6 @@ struct wlr_surface; struct cg_output { struct cg_server *server; struct wlr_output *wlr_output; - struct wlr_scene_output *scene_output; struct wlr_scene_rect *bg; struct wl_listener mode; @@ -56,5 +55,6 @@ void output_configure(struct cg_server *server, struct cg_output *output); void output_set_window_title(struct cg_output *output, const char *title); - +void +output_make_workspace_fullscreen(struct cg_output *output,int ws); #endif diff --git a/parse.c b/parse.c index 32eb363..9cf68c2 100644 --- a/parse.c +++ b/parse.c @@ -736,8 +736,9 @@ parse_command(struct cg_server *server, struct keybinding *keybinding, } else if(strcmp(action, "message") == 0) { keybinding->action = KEYBINDING_DISPLAY_MESSAGE; if(saveptr == NULL) { - *errstr = log_error("Not enough paramaters to \"message\". Expected " - "string to display."); + *errstr = + log_error("Not enough paramaters to \"message\". Expected " + "string to display."); return -1; } keybinding->data.c = strdup(saveptr); @@ -873,8 +874,7 @@ parse_command(struct cg_server *server, struct keybinding *keybinding, keybinding->action = KEYBINDING_SWITCH_MODE; char *mode = strtok_r(NULL, " ", &saveptr); if(mode == NULL) { - *errstr = - log_error("Expected mode after \"mode\". Got nothing."); + *errstr = log_error("Expected mode after \"mode\". Got nothing."); return -1; } int mode_idx = get_mode_index_from_name(server->modes, mode); diff --git a/seat.c b/seat.c index 4f82743..976f6fc 100644 --- a/seat.c +++ b/seat.c @@ -510,12 +510,14 @@ handle_touch_down(struct wl_listener *listener, void *data) { event->y, &lx, &ly); double sx, sy; - struct wlr_scene_node *node=wlr_scene_node_at(&seat->server->scene->node, lx,ly,&sx,&sy); + struct wlr_scene_node *node = + wlr_scene_node_at(&seat->server->scene->node, lx, ly, &sx, &sy); uint32_t serial = 0; - if(node&&node->type == WLR_SCENE_NODE_SURFACE) { + if(node && node->type == WLR_SCENE_NODE_SURFACE) { serial = wlr_seat_touch_notify_down( - seat->seat, wlr_scene_surface_from_node(node)->surface, event->time_msec, event->touch_id, sx, sy); + seat->seat, wlr_scene_surface_from_node(node)->surface, + event->time_msec, event->touch_id, sx, sy); } if(serial && wlr_seat_touch_num_points(seat->seat) == 1) { @@ -554,11 +556,13 @@ handle_touch_motion(struct wl_listener *listener, void *data) { event->y, &lx, &ly); double sx, sy; - struct wlr_scene_node *node=wlr_scene_node_at(&seat->server->scene->node, lx,ly,&sx,&sy); + struct wlr_scene_node *node = + wlr_scene_node_at(&seat->server->scene->node, lx, ly, &sx, &sy); - if(node&&node->type == WLR_SCENE_NODE_SURFACE) { - wlr_seat_touch_point_focus(seat->seat, wlr_scene_surface_from_node(node)->surface, event->time_msec, - event->touch_id, sx, sy); + if(node && node->type == WLR_SCENE_NODE_SURFACE) { + wlr_seat_touch_point_focus(seat->seat, + wlr_scene_surface_from_node(node)->surface, + event->time_msec, event->touch_id, sx, sy); wlr_seat_touch_notify_motion(seat->seat, event->time_msec, event->touch_id, sx, sy); } else { @@ -609,11 +613,11 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time) { struct wlr_seat *wlr_seat = seat->seat; struct wlr_surface *surface = NULL; - struct wlr_scene_node *node=wlr_scene_node_at(&seat->server->scene->node, seat->cursor->x,seat->cursor->y,&sx,&sy); + struct wlr_scene_node *node = wlr_scene_node_at( + &seat->server->scene->node, seat->cursor->x, seat->cursor->y, &sx, &sy); - - if(node&&node->type == WLR_SCENE_NODE_SURFACE) { - surface=wlr_scene_surface_from_node(node)->surface; + if(node && node->type == WLR_SCENE_NODE_SURFACE) { + surface = wlr_scene_surface_from_node(node)->surface; wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); bool focus_changed = wlr_seat->pointer_state.focused_surface != surface; @@ -630,6 +634,31 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time) { } wlr_idle_notify_activity(seat->server->idle, seat->seat); + + /* Check if cursor switched tile */ + struct wlr_output *c_outp = wlr_output_layout_output_at(seat->server->output_layout,seat->cursor->x,seat->cursor->y); + struct cg_output *cg_outp = NULL; + wl_list_for_each(cg_outp,&seat->server->outputs,link) { + if(cg_outp->wlr_output == c_outp) { + break; + } + } + struct cg_tile *c_tile; + bool first=true; + for(c_tile = cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; + first || c_tile != cg_outp->workspaces[cg_outp->curr_workspace]->focused_tile; c_tile = c_tile->next) { + first = false; + double ox=seat->cursor->x,oy=seat->cursor->y; + wlr_output_layout_output_coords(seat->server->output_layout,c_outp,&ox,&oy); + if(c_tile->tile.x<=ox&&c_tile->tile.y<=oy&&c_tile->tile.x+c_tile->tile.width>=ox&&c_tile->tile.y+c_tile->tile.height>=oy) { + break; + } + } + if(seat->cursor_tile != NULL && seat->cursor_tile != c_tile) { + ipc_send_event(seat->server, "{\"event_name\":\"cursor_switch_tile\",\"old_output\":\"%s\",\"old_tile\":\"%d\",\"new_output\":\"%s\",\"new_tile\":\"%d\"}", + seat->cursor_tile->workspace->output->wlr_output->name, seat->cursor_tile->id,c_outp->name,c_tile->id); + } + seat->cursor_tile=c_tile; } static void @@ -676,7 +705,8 @@ drag_icon_update_position(struct cg_drag_icon *drag_icon) { drag_icon->ly = seat->touch_ly; break; } - wlr_scene_node_set_position(drag_icon->scene_node, drag_icon->lx, drag_icon->ly); + wlr_scene_node_set_position(drag_icon->scene_node, drag_icon->lx, + drag_icon->ly); } static void @@ -732,7 +762,8 @@ handle_start_drag(struct wl_listener *listener, void *data) { } drag_icon->seat = seat; drag_icon->wlr_drag_icon = wlr_drag_icon; - drag_icon->scene_node = wlr_scene_subsurface_tree_create(&seat->server->scene->node, wlr_drag_icon->surface); + drag_icon->scene_node = wlr_scene_subsurface_tree_create( + &seat->server->scene->node, wlr_drag_icon->surface); if(!drag_icon->scene_node) { free(drag_icon); return; @@ -966,5 +997,6 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) { process_cursor_motion(seat, -1); struct wlr_box *box = wlr_output_layout_get_box( server->output_layout, view->workspace->output->wlr_output); - wlr_scene_node_set_position(&view->workspace->output->bg->node, box->x, box->y); + wlr_scene_node_set_position(&view->workspace->output->bg->node, box->x, + box->y); } diff --git a/seat.h b/seat.h index a46348b..32ef586 100644 --- a/seat.h +++ b/seat.h @@ -28,6 +28,7 @@ struct cg_seat { uint16_t num_touch; struct wlr_cursor *cursor; + struct cg_tile *cursor_tile; struct wlr_xcursor_manager *xcursor_manager; struct wl_listener cursor_motion; struct wl_listener cursor_motion_absolute; diff --git a/server.c b/server.c index 242fd30..e554a3c 100644 --- a/server.c +++ b/server.c @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include "input_manager.h" #include "output.h" diff --git a/util.c b/util.c index 4ed180b..95e1ea4 100644 --- a/util.c +++ b/util.c @@ -10,8 +10,8 @@ #include #include "util.h" -#include #include +#include int scale_length(int length, int offset, double scale) { diff --git a/view.c b/view.c index 9025c3c..e5f61d8 100644 --- a/view.c +++ b/view.c @@ -12,13 +12,13 @@ #include #include #include -#include #include #include #include -#include -#include #include +#include +#include +#include #include "ipc_server.h" #include "output.h" @@ -99,7 +99,8 @@ view_maximize(struct cg_view *view, struct cg_tile *tile) { view->oy = tile->tile.y; struct wlr_box *box = wlr_output_layout_get_box( view->server->output_layout, view->workspace->output->wlr_output); - wlr_scene_node_set_position(view->scene_node, view->ox+box->x, view->oy+box->y); + wlr_scene_node_set_position(view->scene_node, view->ox + box->x, + view->oy + box->y); view->impl->maximize(view, tile->tile.width, tile->tile.height); view->tile = tile; wlr_scene_node_raise_to_top(view->scene_node); @@ -119,9 +120,9 @@ view_unmap(struct cg_view *view) { } if(view->tile == NULL) { - tile_id=-1; + tile_id = -1; } else { - tile_id=view->tile->id; + tile_id = view->tile->id; } wlr_scene_node_destroy(view->scene_node); @@ -161,9 +162,11 @@ view_unmap(struct cg_view *view) { wl_list_remove(&view->link); view->wlr_surface = NULL; - ipc_send_event(view->workspace->server, - "{\"event_name\":\"view_unmap\",\"view_id\":\"%d\",\"tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", - id, tile_id, ws + 1, output_name, title); + ipc_send_event( + view->workspace->server, + "{\"event_name\":\"view_unmap\",\"view_id\":\"%d\",\"tile_id\":\"%d\"," + "\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", + id, tile_id, ws + 1, output_name, title); } void @@ -172,12 +175,13 @@ view_map(struct cg_view *view, struct wlr_surface *surface, struct cg_output *output = ws->output; view->wlr_surface = surface; - view->scene_node=wlr_scene_subsurface_tree_create(&ws->scene->node, surface); + view->scene_node = + wlr_scene_subsurface_tree_create(&ws->scene->node, surface); if(!view->scene_node) { wl_resource_post_no_memory(surface->resource); return; } - view->scene_node->data=view; + view->scene_node->data = view; view->workspace = ws; #if CG_HAS_XWAYLAND @@ -187,7 +191,8 @@ view_map(struct cg_view *view, struct wlr_surface *surface, wl_list_insert(&ws->unmanaged_views, &view->link); struct wlr_box *box = wlr_output_layout_get_box( view->server->output_layout, view->workspace->output->wlr_output); - wlr_scene_node_set_position(view->scene_node, view->ox+box->x, view->oy+box->y); + wlr_scene_node_set_position(view->scene_node, view->ox + box->x, + view->oy + box->y); } else #endif { @@ -196,15 +201,16 @@ view_map(struct cg_view *view, struct wlr_surface *surface, wl_list_insert(&ws->views, &view->link); } seat_set_focus(output->server->seat, view); - int tile_id=0; - if(view->tile==NULL) { - tile_id=-1; + int tile_id = 0; + if(view->tile == NULL) { + tile_id = -1; } else { - tile_id=view->tile->id; + tile_id = view->tile->id; } ipc_send_event( output->server, - "{\"event_name\":\"view_map\",\"view_id\":\"%d\",\"tile_id\":\"%d\",\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", + "{\"event_name\":\"view_map\",\"view_id\":\"%d\",\"tile_id\":\"%d\"," + "\"workspace\":\"%d\",\"output\":\"%s\",\"view_title\":\"%s\"}", view->id, tile_id, view->workspace->num + 1, view->workspace->output->wlr_output->name, view->impl->get_title(view)); } diff --git a/view.h b/view.h index 9484d58..47a5221 100644 --- a/view.h +++ b/view.h @@ -20,7 +20,7 @@ enum cg_view_type { struct cg_view { struct cg_workspace *workspace; struct cg_server *server; - struct wl_list link; // server::views + struct wl_list link; // server::views struct wlr_surface *wlr_surface; struct cg_tile *tile; struct wlr_scene_node *scene_node; diff --git a/workspace.c b/workspace.c index 4000545..7bfe929 100644 --- a/workspace.c +++ b/workspace.c @@ -12,10 +12,11 @@ #include #include #include -#include #include +#include #include "message.h" +#include "seat.h" #include "output.h" #include "server.h" #include "workspace.h" @@ -56,9 +57,13 @@ full_screen_workspace(struct cg_output *output) { 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) { + return NULL; + } workspace->server = output->server; workspace->num = -1; - workspace->scene = wlr_scene_tree_create(&output->scene_output->scene->node); + workspace->scene = wlr_scene_tree_create(&scene_output->scene->node); if(full_screen_workspace_tiles(output->server->output_layout, output->wlr_output, workspace, &output->server->tiles_curr_id) != 0) { @@ -86,6 +91,9 @@ 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; @@ -100,7 +108,9 @@ workspace_free(struct cg_workspace *workspace) { void workspace_focus(struct cg_output *outp, int ws) { - 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; + 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; } diff --git a/xdg_shell.c b/xdg_shell.c index b5bc24b..c6ce196 100644 --- a/xdg_shell.c +++ b/xdg_shell.c @@ -9,16 +9,16 @@ #define _POSIX_C_SOURCE 200809L -#include #include +#include #include -#include #include +#include #include #include +#include #include #include -#include #include "output.h" #include "server.h" @@ -29,26 +29,28 @@ static struct cg_view * popup_get_view(struct wlr_xdg_popup *popup) { while(true) { - if(popup->parent == NULL || !wlr_surface_is_xdg_surface(popup->parent)) { + if(popup->parent == NULL || + !wlr_surface_is_xdg_surface(popup->parent)) { return NULL; } - struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_from_wlr_surface(popup->parent); + struct wlr_xdg_surface *xdg_surface = + wlr_xdg_surface_from_wlr_surface(popup->parent); switch(xdg_surface->role) { - case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - return xdg_surface->data; - case WLR_XDG_SURFACE_ROLE_POPUP: - popup=xdg_surface->popup; - break; - case WLR_XDG_SURFACE_ROLE_NONE: - return NULL; + case WLR_XDG_SURFACE_ROLE_TOPLEVEL: + return xdg_surface->data; + case WLR_XDG_SURFACE_ROLE_POPUP: + popup = xdg_surface->popup; + break; + case WLR_XDG_SURFACE_ROLE_NONE: + return NULL; } } } static void -xdg_decoration_handle_destroy(struct wl_listener *listener, void *data) -{ - struct cg_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, destroy); +xdg_decoration_handle_destroy(struct wl_listener *listener, void *data) { + struct cg_xdg_decoration *xdg_decoration = + wl_container_of(listener, xdg_decoration, destroy); wl_list_remove(&xdg_decoration->destroy.link); wl_list_remove(&xdg_decoration->request_mode.link); @@ -196,31 +198,31 @@ handle_xdg_shell_surface_destroy(struct wl_listener *listener, void *_data) { view_destroy(view); } -static const struct cg_view_impl xdg_shell_view_impl = { - .get_title = get_title, - .is_primary = is_primary, - .activate = activate, - .close = close, - .maximize = maximize, - .destroy = destroy -}; - +static const struct cg_view_impl xdg_shell_view_impl = {.get_title = get_title, + .is_primary = + is_primary, + .activate = activate, + .close = close, + .maximize = maximize, + .destroy = destroy}; void -handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) -{ - struct cg_server *server = wl_container_of(listener, server, new_xdg_shell_surface); +handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) { + struct cg_server *server = + wl_container_of(listener, server, new_xdg_shell_surface); struct wlr_xdg_surface *xdg_surface = data; - switch (xdg_surface->role) { + switch(xdg_surface->role) { case WLR_XDG_SURFACE_ROLE_TOPLEVEL:; - struct cg_xdg_shell_view *xdg_shell_view = calloc(1, sizeof(struct cg_xdg_shell_view)); - if (!xdg_shell_view) { + struct cg_xdg_shell_view *xdg_shell_view = + calloc(1, sizeof(struct cg_xdg_shell_view)); + if(!xdg_shell_view) { wlr_log(WLR_ERROR, "Failed to allocate XDG Shell view"); return; } - view_init(&xdg_shell_view->view, CG_XDG_SHELL_VIEW, &xdg_shell_view_impl,server); + view_init(&xdg_shell_view->view, CG_XDG_SHELL_VIEW, + &xdg_shell_view_impl, server); xdg_shell_view->xdg_surface = xdg_surface; @@ -230,21 +232,24 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) wl_signal_add(&xdg_surface->events.unmap, &xdg_shell_view->unmap); xdg_shell_view->destroy.notify = handle_xdg_shell_surface_destroy; wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy); - xdg_shell_view->request_fullscreen.notify = handle_xdg_shell_surface_request_fullscreen; - wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &xdg_shell_view->request_fullscreen); + xdg_shell_view->request_fullscreen.notify = + handle_xdg_shell_surface_request_fullscreen; + wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, + &xdg_shell_view->request_fullscreen); xdg_surface->data = xdg_shell_view; break; case WLR_XDG_SURFACE_ROLE_POPUP:; struct wlr_xdg_popup *popup = xdg_surface->popup; struct cg_view *view = popup_get_view(popup); - if (view == NULL) { + if(view == NULL) { return; } struct wlr_scene_node *parent_scene_node = NULL; - struct wlr_xdg_surface *parent = wlr_xdg_surface_from_wlr_surface(popup->parent); - switch (parent->role) { + struct wlr_xdg_surface *parent = + wlr_xdg_surface_from_wlr_surface(popup->parent); + switch(parent->role) { case WLR_XDG_SURFACE_ROLE_TOPLEVEL:; parent_scene_node = view->scene_node; break; @@ -254,13 +259,15 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data) case WLR_XDG_SURFACE_ROLE_NONE: break; } - if (parent_scene_node == NULL) { + if(parent_scene_node == NULL) { return; } - struct wlr_scene_node *popup_scene_node = wlr_scene_xdg_surface_create(parent_scene_node, xdg_surface); - if (popup_scene_node == NULL) { - wlr_log(WLR_ERROR, "Failed to allocate scene-graph node for XDG popup"); + struct wlr_scene_node *popup_scene_node = + wlr_scene_xdg_surface_create(parent_scene_node, xdg_surface); + if(popup_scene_node == NULL) { + wlr_log(WLR_ERROR, + "Failed to allocate scene-graph node for XDG popup"); return; } diff --git a/xwayland.c b/xwayland.c index c3c3a57..3b829ff 100644 --- a/xwayland.c +++ b/xwayland.c @@ -63,6 +63,9 @@ static void activate(struct cg_view *view, bool activate) { struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view); wlr_xwayland_surface_activate(xwayland_view->xwayland_surface, activate); + if(activate) { + wlr_xwayland_surface_restack(xwayland_view->xwayland_surface, NULL, XCB_STACK_MODE_ABOVE); + } } static void @@ -89,8 +92,9 @@ maximize(struct cg_view *view, int width, int height) { struct wlr_box *output_box = wlr_output_layout_get_box( view->server->output_layout, view->server->curr_output->wlr_output); - wlr_xwayland_surface_configure(xwayland_view->xwayland_surface, view->ox+output_box->x, - view->oy+output_box->y, width, height); + wlr_xwayland_surface_configure(xwayland_view->xwayland_surface, + view->ox + output_box->x, + view->oy + output_box->y, width, height); wlr_xwayland_surface_set_maximized(xwayland_view->xwayland_surface, true); } @@ -129,8 +133,8 @@ handle_xwayland_surface_map(struct wl_listener *listener, void *_data) { struct wlr_output_layout *output_layout = view->server->output_layout; struct wlr_box *output_box = wlr_output_layout_get_box( output_layout, view->server->curr_output->wlr_output); - view->ox = xwayland_view->xwayland_surface->x-output_box->x; - view->oy = xwayland_view->xwayland_surface->y-output_box->y; + view->ox = xwayland_view->xwayland_surface->x - output_box->x; + view->oy = xwayland_view->xwayland_surface->y - output_box->y; } view_map(view, xwayland_view->xwayland_surface->surface,