mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 17:31:28 +00:00
Merge pull request #54 from Luminarys/master
Added in basic floating support
This commit is contained in:
commit
b48e8d1b17
|
@ -36,16 +36,24 @@ struct sway_container {
|
||||||
// Not including borders or margins
|
// Not including borders or margins
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
|
// Used for setting floating geometry
|
||||||
|
int desired_width, desired_height;
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
bool visible;
|
bool visible;
|
||||||
|
|
||||||
|
bool is_floating;
|
||||||
|
|
||||||
int weight;
|
int weight;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
list_t *children;
|
list_t *children;
|
||||||
|
|
||||||
|
// Special list for floating windows in workspaces
|
||||||
|
list_t *floating;
|
||||||
|
|
||||||
struct sway_container *parent;
|
struct sway_container *parent;
|
||||||
struct sway_container *focused;
|
struct sway_container *focused;
|
||||||
};
|
};
|
||||||
|
@ -57,6 +65,8 @@ swayc_t *new_workspace(swayc_t * output, const char *name);
|
||||||
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout);
|
swayc_t *new_container(swayc_t *child, enum swayc_layouts layout);
|
||||||
//Creates view as a sibling of current focused container, or as child of a workspace
|
//Creates view as a sibling of current focused container, or as child of a workspace
|
||||||
swayc_t *new_view(swayc_t *sibling, wlc_handle handle);
|
swayc_t *new_view(swayc_t *sibling, wlc_handle handle);
|
||||||
|
//Creates view as a new floating view which is in the active workspace
|
||||||
|
swayc_t *new_floating_view(wlc_handle handle);
|
||||||
|
|
||||||
|
|
||||||
swayc_t *destroy_output(swayc_t *output);
|
swayc_t *destroy_output(swayc_t *output);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "container.h"
|
#include "container.h"
|
||||||
|
#include "handlers.h"
|
||||||
|
|
||||||
struct modifier_key {
|
struct modifier_key {
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -169,6 +170,77 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cmd_floating(struct sway_config *config, int argc, char **argv) {
|
||||||
|
if (strcasecmp(argv[0], "toggle") == 0) {
|
||||||
|
swayc_t *view = get_focused_container(&root_container);
|
||||||
|
// Prevent running floating commands on things like workspaces
|
||||||
|
if (view->type != C_VIEW) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
// Change from nonfloating to floating
|
||||||
|
if (!view->is_floating) {
|
||||||
|
view->is_floating = true;
|
||||||
|
for (i = 0; i < view->parent->children->length; i++) {
|
||||||
|
if (view->parent->children->items[i] == view) {
|
||||||
|
// Try to use desired geometry to set w/h
|
||||||
|
if (view->desired_width != -1) {
|
||||||
|
view->width = view->desired_width;
|
||||||
|
}
|
||||||
|
if (view->desired_height != -1) {
|
||||||
|
view->height = view->desired_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swap from the list of whatever container the view was in
|
||||||
|
// to the workspace->floating list
|
||||||
|
list_del(view->parent->children, i);
|
||||||
|
list_add(active_workspace->floating, view);
|
||||||
|
destroy_container(view->parent);
|
||||||
|
|
||||||
|
// Set the new position of the container and arrange windows
|
||||||
|
view->x = (active_workspace->width - view->width)/2;
|
||||||
|
view->y = (active_workspace->height - view->height)/2;
|
||||||
|
sway_log(L_INFO, "Setting container %p to floating at coordinates X:%d Y:%d, W:%d, H:%d", view, view->x, view->y, view->width, view->height);
|
||||||
|
// Change parent to active_workspace
|
||||||
|
view->parent = active_workspace;
|
||||||
|
arrange_windows(active_workspace, -1, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Delete the view from the floating list and unset its is_floating flag
|
||||||
|
// Using length-1 as the index is safe because the view must be the currently
|
||||||
|
// focused floating output
|
||||||
|
list_del(active_workspace->floating, active_workspace->floating->length - 1);
|
||||||
|
view->is_floating = false;
|
||||||
|
active_workspace->focused = NULL;
|
||||||
|
// Get the properly focused container, and add in the view there
|
||||||
|
swayc_t *focused = focus_pointer();
|
||||||
|
// If focused is null, it's because the currently focused container is a workspace
|
||||||
|
if (focused == NULL) {
|
||||||
|
focused = active_workspace;
|
||||||
|
}
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "Non-floating focused container is %p", focused);
|
||||||
|
|
||||||
|
//Case of focused workspace, just create as child of it
|
||||||
|
if (focused->type == C_WORKSPACE) {
|
||||||
|
add_child(focused, view);
|
||||||
|
}
|
||||||
|
//Regular case, create as sibling of current container
|
||||||
|
else {
|
||||||
|
add_sibling(focused, view);
|
||||||
|
}
|
||||||
|
// Refocus on the view once its been put back into the layout
|
||||||
|
focus_view(view);
|
||||||
|
arrange_windows(active_workspace, -1, -1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
|
static bool cmd_focus(struct sway_config *config, int argc, char **argv) {
|
||||||
if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) {
|
if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -378,6 +450,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "exec", cmd_exec },
|
{ "exec", cmd_exec },
|
||||||
{ "exec_always", cmd_exec_always },
|
{ "exec_always", cmd_exec_always },
|
||||||
{ "exit", cmd_exit },
|
{ "exit", cmd_exit },
|
||||||
|
{ "floating", cmd_floating },
|
||||||
{ "focus", cmd_focus },
|
{ "focus", cmd_focus },
|
||||||
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
||||||
{ "fullscreen", cmd_fullscreen },
|
{ "fullscreen", cmd_fullscreen },
|
||||||
|
|
|
@ -81,6 +81,7 @@ swayc_t *new_workspace(swayc_t * output, const char *name) {
|
||||||
workspace->height = output->height;
|
workspace->height = output->height;
|
||||||
workspace->name = strdup(name);
|
workspace->name = strdup(name);
|
||||||
workspace->visible = true;
|
workspace->visible = true;
|
||||||
|
workspace->floating = create_list();
|
||||||
|
|
||||||
add_child(output, workspace);
|
add_child(output, workspace);
|
||||||
return workspace;
|
return workspace;
|
||||||
|
@ -134,6 +135,12 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
||||||
view->name = strdup(title);
|
view->name = strdup(title);
|
||||||
view->visible = true;
|
view->visible = true;
|
||||||
|
|
||||||
|
view->desired_width = -1;
|
||||||
|
view->desired_height = -1;
|
||||||
|
|
||||||
|
// TODO: properly set this
|
||||||
|
view->is_floating = false;
|
||||||
|
|
||||||
//Case of focused workspace, just create as child of it
|
//Case of focused workspace, just create as child of it
|
||||||
if (sibling->type == C_WORKSPACE) {
|
if (sibling->type == C_WORKSPACE) {
|
||||||
add_child(sibling, view);
|
add_child(sibling, view);
|
||||||
|
@ -145,6 +152,38 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swayc_t *new_floating_view(wlc_handle handle) {
|
||||||
|
const char *title = wlc_view_get_title(handle);
|
||||||
|
swayc_t *view = new_swayc(C_VIEW);
|
||||||
|
sway_log(L_DEBUG, "Adding new view %u:%s as a floating view",
|
||||||
|
(unsigned int)handle, title);
|
||||||
|
//Setup values
|
||||||
|
view->handle = handle;
|
||||||
|
view->name = strdup(title);
|
||||||
|
view->visible = true;
|
||||||
|
|
||||||
|
// Set the geometry of the floating view
|
||||||
|
const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);
|
||||||
|
|
||||||
|
view->x = geometry->origin.x;
|
||||||
|
view->y = geometry->origin.y;
|
||||||
|
view->width = geometry->size.w;
|
||||||
|
view->height = geometry->size.h;
|
||||||
|
|
||||||
|
view->desired_width = view->width;
|
||||||
|
view->desired_height = view->height;
|
||||||
|
|
||||||
|
view->is_floating = true;
|
||||||
|
|
||||||
|
//Case of focused workspace, just create as child of it
|
||||||
|
list_add(active_workspace->floating, view);
|
||||||
|
view->parent = active_workspace;
|
||||||
|
if (active_workspace->focused == NULL) {
|
||||||
|
active_workspace->focused = view;
|
||||||
|
}
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
swayc_t *destroy_output(swayc_t *output) {
|
swayc_t *destroy_output(swayc_t *output) {
|
||||||
if (output->children->length == 0) {
|
if (output->children->length == 0) {
|
||||||
|
@ -192,23 +231,32 @@ swayc_t *destroy_view(swayc_t *view) {
|
||||||
if (parent->type == C_CONTAINER) {
|
if (parent->type == C_CONTAINER) {
|
||||||
return destroy_container(parent);
|
return destroy_container(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
|
swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) {
|
||||||
if (!container->children) {
|
if (!container->children) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
// Special case for checking floating stuff
|
||||||
int i;
|
int i;
|
||||||
|
if (container->type == C_WORKSPACE) {
|
||||||
|
for (i = 0; i < container->floating->length; ++i) {
|
||||||
|
swayc_t *child = container->floating->items[i];
|
||||||
|
if (test(child, data)) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = container->children->items[i];
|
||||||
if (test(child, data)) {
|
if (test(child, data)) {
|
||||||
return child;
|
return child;
|
||||||
} else {
|
} else {
|
||||||
swayc_t *_ = find_container(child, test, data);
|
swayc_t *res = find_container(child, test, data);
|
||||||
if (_) {
|
if (res) {
|
||||||
return _;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "handlers.h"
|
#include "handlers.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "workspace.h"
|
#include "workspace.h"
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
static struct wlc_origin mouse_origin;
|
static struct wlc_origin mouse_origin;
|
||||||
|
|
||||||
|
@ -88,17 +89,24 @@ static void handle_output_focused(wlc_handle output, bool focus) {
|
||||||
static bool handle_view_created(wlc_handle handle) {
|
static bool handle_view_created(wlc_handle handle) {
|
||||||
swayc_t *focused = get_focused_container(&root_container);
|
swayc_t *focused = get_focused_container(&root_container);
|
||||||
uint32_t type = wlc_view_get_type(handle);
|
uint32_t type = wlc_view_get_type(handle);
|
||||||
//If override_redirect/unmanaged/popup/modal/splach
|
// If override_redirect/unmanaged/popup/modal/splach
|
||||||
if (type) {
|
if (type) {
|
||||||
sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type);
|
sway_log(L_DEBUG,"Unmanaged window of type %x left alone", type);
|
||||||
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
|
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
|
||||||
if (type & WLC_BIT_UNMANAGED) {
|
if (type & WLC_BIT_UNMANAGED) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//for things like Dmenu
|
// For things like Dmenu
|
||||||
if (type & WLC_BIT_OVERRIDE_REDIRECT) {
|
if (type & WLC_BIT_OVERRIDE_REDIRECT) {
|
||||||
wlc_view_focus(handle);
|
wlc_view_focus(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Float popups
|
||||||
|
if (type & WLC_BIT_POPUP) {
|
||||||
|
swayc_t *view = new_floating_view(handle);
|
||||||
|
focus_view(view);
|
||||||
|
arrange_windows(active_workspace, -1, -1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
swayc_t *view = new_view(focused, handle);
|
swayc_t *view = new_view(focused, handle);
|
||||||
//Set maximize flag for windows.
|
//Set maximize flag for windows.
|
||||||
|
@ -118,6 +126,24 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
|
|
||||||
static void handle_view_destroyed(wlc_handle handle) {
|
static void handle_view_destroyed(wlc_handle handle) {
|
||||||
sway_log(L_DEBUG, "Destroying window %u", (unsigned int)handle);
|
sway_log(L_DEBUG, "Destroying window %u", (unsigned int)handle);
|
||||||
|
|
||||||
|
// Properly handle unmanaged views
|
||||||
|
uint32_t type = wlc_view_get_type(handle);
|
||||||
|
if (type) {
|
||||||
|
wlc_view_set_state(handle, WLC_BIT_ACTIVATED, true);
|
||||||
|
sway_log(L_DEBUG,"Unmanaged window of type %x was destroyed", type);
|
||||||
|
if (type & WLC_BIT_UNMANAGED) {
|
||||||
|
focus_view(focus_pointer());
|
||||||
|
arrange_windows(active_workspace, -1, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type & WLC_BIT_OVERRIDE_REDIRECT) {
|
||||||
|
focus_view(focus_pointer());
|
||||||
|
arrange_windows(active_workspace, -1, -1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
swayc_t *view = get_swayc_for_handle(handle, &root_container);
|
swayc_t *view = get_swayc_for_handle(handle, &root_container);
|
||||||
swayc_t *parent;
|
swayc_t *parent;
|
||||||
swayc_t *focused = get_focused_container(&root_container);
|
swayc_t *focused = get_focused_container(&root_container);
|
||||||
|
@ -135,8 +161,23 @@ static void handle_view_focus(wlc_handle view, bool focus) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry) {
|
static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geometry* geometry) {
|
||||||
// deny that shit
|
// If the view is floating, then apply the geometry.
|
||||||
|
// Otherwise save the desired width/height for the view.
|
||||||
|
// This will not do anything for the time being as WLC improperly sends geometry requests
|
||||||
|
swayc_t *view = get_swayc_for_handle(handle, &root_container);
|
||||||
|
if (view) {
|
||||||
|
view->desired_width = geometry->size.w;
|
||||||
|
view->desired_height = geometry->size.h;
|
||||||
|
|
||||||
|
if (view->is_floating) {
|
||||||
|
view->width = view->desired_width;
|
||||||
|
view->height = view->desired_height;
|
||||||
|
view->x = geometry->origin.x;
|
||||||
|
view->y = geometry->origin.y;
|
||||||
|
arrange_windows(view->parent, -1, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) {
|
static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) {
|
||||||
|
|
|
@ -65,10 +65,20 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
||||||
|
|
||||||
swayc_t *remove_child(swayc_t *parent, swayc_t *child) {
|
swayc_t *remove_child(swayc_t *parent, swayc_t *child) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
// Special case for floating views
|
||||||
if (parent->children->items[i] == child) {
|
if (child->is_floating) {
|
||||||
list_del(parent->children, i);
|
for (i = 0; i < parent->floating->length; ++i) {
|
||||||
break;
|
if (parent->floating->items[i] == child) {
|
||||||
|
list_del(parent->floating, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < parent->children->length; ++i) {
|
||||||
|
if (parent->children->items[i] == child) {
|
||||||
|
list_del(parent->children, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parent->focused == child) {
|
if (parent->focused == child) {
|
||||||
|
@ -192,6 +202,33 @@ void arrange_windows(swayc_t *container, int width, int height) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Arrage floating layouts for workspaces last
|
||||||
|
if (container->type == C_WORKSPACE) {
|
||||||
|
for (i = 0; i < container->floating->length; ++i) {
|
||||||
|
swayc_t *view = ((swayc_t *)container->floating->items[i]);
|
||||||
|
// Set the geometry
|
||||||
|
struct wlc_geometry geometry = {
|
||||||
|
.origin = {
|
||||||
|
.x = view->x,
|
||||||
|
.y = view->y
|
||||||
|
},
|
||||||
|
.size = {
|
||||||
|
.w = view->width,
|
||||||
|
.h = view->height
|
||||||
|
}
|
||||||
|
};
|
||||||
|
wlc_view_set_geometry(view->handle, &geometry);
|
||||||
|
|
||||||
|
// Bring the views to the front in order of the list, the list
|
||||||
|
// will be kept up to date so that more recently focused views
|
||||||
|
// have higher indexes
|
||||||
|
// This is conditional on there not being a fullscreen view in the workspace
|
||||||
|
if (!(wlc_view_get_state(container->focused->handle) & WLC_BIT_FULLSCREEN)) {
|
||||||
|
wlc_view_bring_to_front(view->handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
layout_log(&root_container, 0);
|
layout_log(&root_container, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +236,18 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) {
|
||||||
if (parent->children == NULL) {
|
if (parent->children == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Search for floating workspaces
|
||||||
int i;
|
int i;
|
||||||
|
if (parent->type == C_WORKSPACE) {
|
||||||
|
for (i = 0; i < parent->floating->length; ++i) {
|
||||||
|
swayc_t *child = parent->floating->items[i];
|
||||||
|
if (child->handle == handle) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
for (i = 0; i < parent->children->length; ++i) {
|
||||||
swayc_t *child = parent->children->items[i];
|
swayc_t *child = parent->children->items[i];
|
||||||
if (child->handle == handle) {
|
if (child->handle == handle) {
|
||||||
|
|
|
@ -255,5 +255,18 @@ void layout_log(const swayc_t *c, int depth) {
|
||||||
for (i = 0; i < depth; ++i) fputc(' ', stderr);
|
for (i = 0; i < depth; ++i) fputc(' ', stderr);
|
||||||
fprintf(stderr,")\n");
|
fprintf(stderr,")\n");
|
||||||
}
|
}
|
||||||
|
if (c->type == C_WORKSPACE) {
|
||||||
|
e = c->floating?c->floating->length:0;
|
||||||
|
for (i = 0; i < depth; ++i) fputc(' ', stderr);
|
||||||
|
if (e) {
|
||||||
|
for (i = 0; i < depth; ++i) fputc(' ', stderr);
|
||||||
|
fprintf(stderr,"(\n");
|
||||||
|
for (i = 0; i < e; ++i) {
|
||||||
|
layout_log(c->floating->items[i], depth + 1);
|
||||||
|
}
|
||||||
|
for (i = 0; i < depth; ++i) fputc(' ', stderr);
|
||||||
|
fprintf(stderr,")\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* XXX:DEBUG:XXX */
|
/* XXX:DEBUG:XXX */
|
||||||
|
|
Loading…
Reference in a new issue