gimp but for windows: a wayland compositor
git clone https://github.com/m-col/wimp
Files | Refs | Readme

-rw-r--r-- src/scratchpad.c


      1 #include "shell.h"
      2 #include "scratchpad.h"
      3 #include "types.h"
      4 
      5 
      6 struct scratchpad *scratchpad_from_view(struct view *view) {
      7     struct scratchpad *scratchpad;
      8 
      9     wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
     10 	if (view == scratchpad->view) {
     11 	    return scratchpad;
     12 	}
     13     }
     14 
     15     return NULL;
     16 }
     17 
     18 
     19 struct scratchpad *scratchpad_from_id(int id) {
     20     struct scratchpad *scratchpad;
     21 
     22     wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
     23 	if (scratchpad->id == id) {
     24 	    return scratchpad;
     25 	}
     26     }
     27 
     28     return NULL;
     29 }
     30 
     31 
     32 void scratchpad_apply_geo(struct scratchpad *scratchpad) {
     33     struct wlr_output *output =
     34 	wlr_output_layout_output_at(wimp.output_layout, wimp.cursor->x, wimp.cursor->y);
     35     struct wlr_box *ogeo = wlr_output_layout_get_box(wimp.output_layout, output);
     36     struct view *view = scratchpad->view;
     37     struct wlr_box *geo = &scratchpad->geo;
     38 
     39     if (geo->x > 0) {
     40 	view->x = geo->x;
     41     } else {
     42 	view->x = ogeo->x - (ogeo->width * geo->x / 100);
     43     }
     44     if (geo->y > 0) {
     45 	view->y = geo->y;
     46     } else {
     47 	view->y = ogeo->y - (ogeo->height * geo->y / 100);
     48     }
     49 
     50     struct wlr_box *sgeo = &view->surface->geometry;
     51     if (geo->width > 0) {
     52 	sgeo->width = geo->width;
     53     } else {
     54 	sgeo->width = - ogeo->width * geo->width / 100;
     55     }
     56     if (geo->height > 0) {
     57 	sgeo->height = geo->height;
     58     } else {
     59 	sgeo->height = - ogeo->height * geo->height / 100;
     60     }
     61     wlr_xdg_toplevel_set_size(view->surface, sgeo->width, sgeo->height);
     62 }
     63 
     64 
     65 
     66 bool catch_scratchpad(struct view *view) {
     67     pid_t pid;
     68     wl_client_get_credentials(view->surface->client->client, &pid, NULL, NULL);
     69 
     70     struct scratchpad *scratchpad;
     71     wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
     72 	if (scratchpad->pid == pid) {
     73 	    scratchpad->view = view;
     74 	    view->is_scratchpad = true;
     75 	    return true;
     76 	}
     77     }
     78     return false;
     79 }
     80 
     81 
     82 void drop_scratchpads() {
     83     struct scratchpad *scratchpad, *tmp;
     84     wl_list_for_each_safe(scratchpad, tmp, &wimp.scratchpads, link) {
     85 	if (scratchpad->view) {
     86 	    scratchpad->view->is_scratchpad = false;
     87 	    wl_list_insert(&wimp.current_desk->views, &scratchpad->view->link);
     88 	    map_view(scratchpad->view);
     89 	}
     90 	wl_list_remove(&scratchpad->link);
     91 	free(scratchpad->command);
     92 	free(scratchpad);
     93     }
     94 }
     95