1
1
mirror of https://github.com/swaywm/sway synced 2024-11-18 04:33:59 +01:00

IPC: Trigger move events for scratchpad containers

This patch allows IPC clients to receive window::move events
when containers are moved to scratchpad or when hidden containers
are shown via "scratchpad show" command.
This commit is contained in:
Mihai Coman 2018-11-21 05:42:04 +02:00
parent c2921b2e61
commit 6aafdd2321

@ -5,6 +5,7 @@
#include <wlr/types/wlr_output_layout.h>
#include "sway/desktop/transaction.h"
#include "sway/input/seat.h"
#include "sway/ipc-server.h"
#include "sway/output.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
@ -75,6 +76,8 @@ void root_scratchpad_add_container(struct sway_container *con) {
arrange_workspace(workspace);
seat_set_focus(seat, seat_get_focus_inactive(seat, &workspace->node));
}
ipc_event_window(con, "move");
}
void root_scratchpad_remove_container(struct sway_container *con) {
@ -85,45 +88,51 @@ void root_scratchpad_remove_container(struct sway_container *con) {
int index = list_find(root->scratchpad, con);
if (index != -1) {
list_del(root->scratchpad, index);
ipc_event_window(con, "move");
}
}
void root_scratchpad_show(struct sway_container *con) {
struct sway_seat *seat = input_manager_current_seat();
struct sway_workspace *ws = seat_get_focused_workspace(seat);
struct sway_workspace *new_ws = seat_get_focused_workspace(seat);
struct sway_workspace *old_ws = con->workspace;
// If the current con or any of its parents are in fullscreen mode, we
// first need to disable it before showing the scratchpad con.
if (ws->fullscreen) {
container_set_fullscreen(ws->fullscreen, false);
// If the current con or any of its parents are in fullscreen mode, we
// first need to disable it before showing the scratchpad con.
if (new_ws->fullscreen) {
container_set_fullscreen(new_ws->fullscreen, false);
}
// Show the container
if (con->workspace) {
if (old_ws) {
container_detach(con);
}
workspace_add_floating(ws, con);
workspace_add_floating(new_ws, con);
// Make sure the container's center point overlaps this workspace
double center_lx = con->x + con->width / 2;
double center_ly = con->y + con->height / 2;
struct wlr_box workspace_box;
workspace_get_box(ws, &workspace_box);
workspace_get_box(new_ws, &workspace_box);
if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) {
// Maybe resize it
if (con->width > ws->width || con->height > ws->height) {
if (con->width > new_ws->width || con->height > new_ws->height) {
container_init_floating(con);
}
// Center it
double new_lx = ws->x + (ws->width - con->width) / 2;
double new_ly = ws->y + (ws->height - con->height) / 2;
double new_lx = new_ws->x + (new_ws->width - con->width) / 2;
double new_ly = new_ws->y + (new_ws->height - con->height) / 2;
container_floating_move_to(con, new_lx, new_ly);
}
arrange_workspace(ws);
arrange_workspace(new_ws);
seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node));
if (new_ws != old_ws) {
ipc_event_window(con, "move");
}
}
void root_scratchpad_hide(struct sway_container *con) {
@ -137,6 +146,8 @@ void root_scratchpad_hide(struct sway_container *con) {
seat_set_focus(seat, seat_get_focus_inactive(seat, &ws->node));
}
list_move_to_end(root->scratchpad, con);
ipc_event_window(con, "move");
}
struct pid_workspace {