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

-rw-r--r-- src/desk.c


      1 #include "config.h"
      2 #include "desk.h"
      3 #include "output.h"
      4 #include "scratchpad.h"
      5 #include "shell.h"
      6 #include "types.h"
      7 
      8 
      9 static void add_desk() {
     10     struct desk *desk = calloc(1, sizeof(struct desk));
     11     wl_list_insert(wimp.desks.prev, &desk->link);
     12     wl_list_init(&desk->views);
     13     assign_colour("#31475c", desk->background);
     14     assign_colour("#3e3e73", desk->border_normal);
     15     assign_colour("#31315c", desk->corner_normal);
     16     assign_colour("#47315c", desk->border_focus);
     17     assign_colour("#7e5992", desk->corner_focus);
     18     desk->border_width = 6;
     19     desk->wallpaper = NULL;
     20     desk->index = wimp.desk_count;
     21     desk->zoom = 1;
     22     desk->fullscreened = NULL;
     23     wimp.desk_count++;
     24 
     25     if (!wimp.current_desk) {
     26 	wimp.current_desk = wl_container_of(wimp.desks.next, wimp.current_desk, link);
     27     }
     28 }
     29 
     30 
     31 static void remove_desk() {
     32     struct desk *last = wl_container_of(wimp.desks.prev, last, link);
     33     if (last == wimp.current_desk) {
     34 	set_desk(wl_container_of(wimp.desks.next, last, link));
     35     }
     36     struct view *view, *tview;
     37     wl_list_for_each_safe(view, tview, &last->views, link) {
     38 	view_to_desk(view, 0);
     39     };
     40     wl_list_remove(&last->link);
     41     free(last->wallpaper);
     42     free(last);
     43     wimp.desk_count--;
     44 }
     45 
     46 
     47 void configure_desks(int wanted) {
     48     while (wanted > wimp.desk_count) {
     49 	add_desk();
     50     }
     51     while (wanted < wimp.desk_count) {
     52 	remove_desk();
     53     }
     54 }
     55 
     56 
     57 void set_desk(struct desk *desk) {
     58     if (desk == wimp.current_desk) {
     59 	return;
     60     }
     61 
     62     wimp.current_desk = desk;
     63     damage_all_outputs();
     64 
     65     // If a scratchpad is focussed, keep it focussed.
     66     struct scratchpad *scratchpad;
     67     wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
     68 	if (scratchpad->view && scratchpad->is_mapped) {
     69 	    if (scratchpad->view->surface->surface == wimp.seat->keyboard_state.focused_surface) {
     70 		return;
     71 	    }
     72 	}
     73     }
     74 
     75     // Otherwise focus the next view on the new desktop if there is one.
     76     if (wl_list_empty(&desk->views)) {
     77 	focus_view(NULL, NULL);
     78     } else {
     79 	struct view *view = wl_container_of(desk->views.next, view, link);
     80 	focus_view(view, NULL);
     81     }
     82 }
     83 
     84 
     85 static struct desk *desk_from_index(int index) {
     86     struct desk *desk;
     87     wl_list_for_each(desk, &wimp.desks, link) {
     88 	if (desk->index == index) {
     89 	    return desk;
     90 	}
     91     }
     92     return NULL;
     93 }
     94 
     95 
     96 void view_to_desk(struct view *view, int index) {
     97     struct desk *desk = desk_from_index(index);
     98     if (desk) {
     99 	wl_list_remove(&view->link);
    100 	wl_list_insert(&desk->views, &view->link);
    101 	if (!wl_list_empty(&wimp.current_desk->views)) {
    102 	    struct view *next_view = wl_container_of(wimp.current_desk->views.next, view, link);
    103 	    focus_view(next_view, NULL);
    104 	}
    105     }
    106 }
    107