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

Commit eed3b6da3c36e7fab2bd17a89567ecfbebca6fc4
Parent: 4f9ea5c9e9309cfdb7eea01e3dbbbe87584fd4f3
Author: mcol <mcol@posteo.net>
Date: 2021-02-06 14:25:17 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-02-06 14:25:17 +0000

move scratchpad functions into dedicated file

src/shell.c Modified

@@ -2,55 +2,10 @@
 #include <wlr/util/edges.h>
 
 #include "action.h"
+#include "scratchpad.h"
 #include "types.h"
 
 
-static struct scratchpad *scratchpad_from_view(struct view *view) {
-    struct scratchpad *scratchpad;
-
-    wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
-	if (view == scratchpad->view) {
-	    return scratchpad;
-	}
-    }
-
-    return NULL;
-}
-
-
-static void scratchpad_apply_geo(struct scratchpad *scratchpad) {
-    struct wlr_output *output =
-	wlr_output_layout_output_at(wimp.output_layout, wimp.cursor->x, wimp.cursor->y);
-    struct wlr_box *ogeo = wlr_output_layout_get_box(wimp.output_layout, output);
-    struct view *view = scratchpad->view;
-    struct wlr_box *geo = &scratchpad->geo;
-
-    if (geo->x > 0) {
-	view->x = geo->x;
-    } else {
-	view->x = ogeo->x - (ogeo->width * geo->x / 100);
-    }
-    if (geo->y > 0) {
-	view->y = geo->y;
-    } else {
-	view->y = ogeo->y - (ogeo->height * geo->y / 100);
-    }
-
-    struct wlr_box *sgeo = &view->surface->geometry;
-    if (geo->width > 0) {
-	sgeo->width = geo->width;
-    } else {
-	sgeo->width = - ogeo->width * geo->width / 100;
-    }
-    if (geo->height > 0) {
-	sgeo->height = geo->height;
-    } else {
-	sgeo->height = - ogeo->height * geo->height / 100;
-    }
-    wlr_xdg_toplevel_set_size(view->surface, sgeo->width, sgeo->height);
-}
-
-
 void unmap_view(struct view *view) {
     wl_signal_emit(&view->surface->events.unmap, view);
 }
@@ -79,12 +34,8 @@
     struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
 
     if (view->is_scratchpad) {
-	struct scratchpad *scratchpad;
-	wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
-	    if (scratchpad->view == view) {
-		scratchpad->is_mapped = true;
-	    }
-	}
+	struct scratchpad *scratchpad = scratchpad_from_view(view);
+	scratchpad->is_mapped = true;
     } else {
 	wl_list_remove(&view->link);
 	wl_list_insert(&wimp.current_desk->views, &view->link);
@@ -180,8 +131,8 @@
 
     if (view->is_scratchpad) {
 	struct scratchpad *scratchpad = scratchpad_from_view(view);
-	scratchpad->is_mapped = true;
 	scratchpad_apply_geo(scratchpad);
+	scratchpad->is_mapped = true;
     }
 
     if (wimp.can_steal_focus) {
@@ -296,18 +247,8 @@
     wl_signal_add(&toplevel->events.request_fullscreen, &view->request_fullscreen_listener);
 
     if (wimp.scratchpad_waiting) {
-	pid_t pid;
-	wl_client_get_credentials(surface->client->client, &pid, NULL, NULL);
-	struct scratchpad *scratchpad;
-	wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
-	    if (scratchpad->pid == pid) {
-		scratchpad->view = view;
-		view->is_scratchpad = true;
-		view->x = 50;
-		view->y = 50;
-		map_view(view);
-		return;
-	    }
+	if (catch_scratchpad(view)) {
+	    return;
 	}
     }
 

src/scratchpad.h Added

@@ -0,0 +1,10 @@
+#ifndef DESKWM_SCRATCHPAD_H
+#define DESKWM_SCRATCHPAD_H
+
+#include "types.h"
+
+struct scratchpad *scratchpad_from_view(struct view *view);
+void scratchpad_apply_geo(struct scratchpad *scratchpad);
+bool catch_scratchpad(struct view *view);
+
+#endif

src/scratchpad.c Added

@@ -0,0 +1,67 @@
+#include "shell.h"
+#include "scratchpad.h"
+#include "types.h"
+
+
+struct scratchpad *scratchpad_from_view(struct view *view) {
+    struct scratchpad *scratchpad;
+
+    wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
+	if (view == scratchpad->view) {
+	    return scratchpad;
+	}
+    }
+
+    return NULL;
+}
+
+
+void scratchpad_apply_geo(struct scratchpad *scratchpad) {
+    struct wlr_output *output =
+	wlr_output_layout_output_at(wimp.output_layout, wimp.cursor->x, wimp.cursor->y);
+    struct wlr_box *ogeo = wlr_output_layout_get_box(wimp.output_layout, output);
+    struct view *view = scratchpad->view;
+    struct wlr_box *geo = &scratchpad->geo;
+
+    if (geo->x > 0) {
+	view->x = geo->x;
+    } else {
+	view->x = ogeo->x - (ogeo->width * geo->x / 100);
+    }
+    if (geo->y > 0) {
+	view->y = geo->y;
+    } else {
+	view->y = ogeo->y - (ogeo->height * geo->y / 100);
+    }
+
+    struct wlr_box *sgeo = &view->surface->geometry;
+    if (geo->width > 0) {
+	sgeo->width = geo->width;
+    } else {
+	sgeo->width = - ogeo->width * geo->width / 100;
+    }
+    if (geo->height > 0) {
+	sgeo->height = geo->height;
+    } else {
+	sgeo->height = - ogeo->height * geo->height / 100;
+    }
+    wlr_xdg_toplevel_set_size(view->surface, sgeo->width, sgeo->height);
+}
+
+
+
+bool catch_scratchpad(struct view *view) {
+    pid_t pid;
+    wl_client_get_credentials(view->surface->client->client, &pid, NULL, NULL);
+
+    struct scratchpad *scratchpad;
+    wl_list_for_each(scratchpad, &wimp.scratchpads, link) {
+	if (scratchpad->pid == pid) {
+	    scratchpad->view = view;
+	    view->is_scratchpad = true;
+	    map_view(view);
+	    return true;
+	}
+    }
+    return false;
+}

src/config.c Modified

@@ -263,7 +263,7 @@
     { "maximize", &maximize, NULL },
     { "reload_config", &reload_config, NULL },
     { "send_to_desk", &send_to_desk, &str_handler },
-    { "scratchpad", &scratchpad, &scratchpad_handler },
+    { "scratchpad", &toggle_scratchpad, &scratchpad_handler },
 };
 
 

src/action.h Modified

@@ -26,6 +26,6 @@
 void maximize(void *data);
 void reload_config(void *data);
 void send_to_desk(void *data);
-void scratchpad(void *data);
+void toggle_scratchpad(void *data);
 
 #endif

src/action.c Modified

@@ -402,7 +402,7 @@
 }
 
 
-void scratchpad(void *data) {
+void toggle_scratchpad(void *data) {
     int id = *(int *)data;
     struct scratchpad *scratchpad;