Merge pull request #266 from sce/sticky_floats_0

workspace: Learn sticky.
This commit is contained in:
Drew DeVault 2015-11-27 10:20:16 -07:00
commit b7702eb34c
5 changed files with 53 additions and 2 deletions

View file

@ -74,6 +74,7 @@ struct sway_container {
bool visible; bool visible;
bool is_floating; bool is_floating;
bool is_focused; bool is_focused;
bool sticky; // floating view always visible on its output
// Attributes that mostly views have. // Attributes that mostly views have.
char *name; char *name;

View file

@ -166,6 +166,10 @@ Commands
**splitv**:: **splitv**::
Equivalent to **split vertical**. Equivalent to **split vertical**.
**sticky** <enable|disable|toggle>::
If enabled and the windows is floating it will always be present on the active
workspace on that output.
**workspace** <name>:: **workspace** <name>::
Switches to the specified workspace. Switches to the specified workspace.

View file

@ -33,7 +33,6 @@ struct cmd_handler {
}; };
static sway_cmd cmd_bindsym; static sway_cmd cmd_bindsym;
static sway_cmd cmd_orientation;
static sway_cmd cmd_debuglog; static sway_cmd cmd_debuglog;
static sway_cmd cmd_exec; static sway_cmd cmd_exec;
static sway_cmd cmd_exec_always; static sway_cmd cmd_exec_always;
@ -51,6 +50,7 @@ static sway_cmd cmd_log_colors;
static sway_cmd cmd_mode; static sway_cmd cmd_mode;
static sway_cmd cmd_mouse_warping; static sway_cmd cmd_mouse_warping;
static sway_cmd cmd_move; static sway_cmd cmd_move;
static sway_cmd cmd_orientation;
static sway_cmd cmd_output; static sway_cmd cmd_output;
static sway_cmd cmd_reload; static sway_cmd cmd_reload;
static sway_cmd cmd_resize; static sway_cmd cmd_resize;
@ -59,6 +59,7 @@ static sway_cmd cmd_set;
static sway_cmd cmd_split; static sway_cmd cmd_split;
static sway_cmd cmd_splith; static sway_cmd cmd_splith;
static sway_cmd cmd_splitv; static sway_cmd cmd_splitv;
static sway_cmd cmd_sticky;
static sway_cmd cmd_workspace; static sway_cmd cmd_workspace;
static sway_cmd cmd_ws_auto_back_and_forth; static sway_cmd cmd_ws_auto_back_and_forth;
@ -1237,6 +1238,28 @@ static struct cmd_results *cmd_splith(int argc, char **argv) {
return _do_split(argc, argv, L_HORIZ); return _do_split(argc, argv, L_HORIZ);
} }
static struct cmd_results *cmd_sticky(int argc, char **argv) {
struct cmd_results *error = NULL;
if (config->reading) return cmd_results_new(CMD_FAILURE, "sticky", "Can't be used in config file.");
if (!config->active) return cmd_results_new(CMD_FAILURE, "sticky", "Can only be used when sway is running.");
if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) {
return error;
}
char *action = argv[0];
swayc_t *cont = get_focused_view(&root_container);
if (strcmp(action, "toggle") == 0) {
cont->sticky = !cont->sticky;
} else if (strcmp(action, "enable") == 0) {
cont->sticky = true;
} else if (strcmp(action, "disable") == 0) {
cont->sticky = false;
} else {
return cmd_results_new(CMD_FAILURE, "sticky",
"Expected 'sticky enable|disable|toggle'");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_results *cmd_log_colors(int argc, char **argv) { static struct cmd_results *cmd_log_colors(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file."); if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file.");
@ -1416,6 +1439,7 @@ static struct cmd_handler handlers[] = {
{ "split", cmd_split }, { "split", cmd_split },
{ "splith", cmd_splith }, { "splith", cmd_splith },
{ "splitv", cmd_splitv }, { "splitv", cmd_splitv },
{ "sticky", cmd_sticky },
{ "workspace", cmd_workspace }, { "workspace", cmd_workspace },
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
}; };

View file

@ -226,6 +226,7 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
view->app_id = app_id ? strdup(app_id) : NULL; view->app_id = app_id ? strdup(app_id) : NULL;
view->visible = true; view->visible = true;
view->is_focused = true; view->is_focused = true;
view->sticky = false;
// Setup geometry // Setup geometry
const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);
view->width = 0; view->width = 0;
@ -261,6 +262,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
const char *app_id = wlc_view_get_app_id(handle); const char *app_id = wlc_view_get_app_id(handle);
view->app_id = app_id ? strdup(app_id) : NULL; view->app_id = app_id ? strdup(app_id) : NULL;
view->visible = true; view->visible = true;
view->sticky = false;
// Set the geometry of the floating view // Set the geometry of the floating view
const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); const struct wlc_geometry* geometry = wlc_view_get_geometry(handle);

View file

@ -221,11 +221,31 @@ bool workspace_switch(swayc_t *workspace) {
strcpy(prev_workspace_name, active_ws->name); strcpy(prev_workspace_name, active_ws->name);
} }
// move sticky containers
if (swayc_parent_by_type(active_ws, C_OUTPUT) == swayc_parent_by_type(workspace, C_OUTPUT)) {
// don't change list while traversing it, use intermediate list instead
list_t *stickies = create_list();
for (int i = 0; i < active_ws->floating->length; i++) {
swayc_t *cont = active_ws->floating->items[i];
if (cont->sticky) {
list_add(stickies, cont);
}
}
for (int i = 0; i < stickies->length; i++) {
swayc_t *cont = stickies->items[i];
sway_log(L_DEBUG, "Moving sticky container %p to %p:%s",
cont, workspace, workspace->name);
swayc_t *parent = remove_child(cont);
add_floating(workspace, cont);
// Destroy old container if we need to
destroy_container(parent);
}
list_free(stickies);
}
sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
if (!set_focused_container(get_focused_view(workspace))) { if (!set_focused_container(get_focused_view(workspace))) {
return false; return false;
} }
arrange_windows(workspace, -1, -1); arrange_windows(workspace, -1, -1);
return true; return true;
} }