Fix switching between focused outputs

master
Drew DeVault 9 years ago
parent 868cb3ca71
commit a64b10df83

@ -37,6 +37,10 @@ static void free_swayc(swayc_t *c) {
/* New containers */ /* New containers */
static bool workspace_test(swayc_t *view, void *name) {
return strcasecmp(view->name, (char *)name);
}
swayc_t *new_output(wlc_handle handle) { swayc_t *new_output(wlc_handle handle) {
const struct wlc_size* size = wlc_output_get_resolution(handle); const struct wlc_size* size = wlc_output_get_resolution(handle);
const char *name = wlc_output_get_name(handle); const char *name = wlc_output_get_name(handle);
@ -58,6 +62,10 @@ swayc_t *new_output(wlc_handle handle) {
struct workspace_output *wso = config->workspace_outputs->items[i]; struct workspace_output *wso = config->workspace_outputs->items[i];
if (strcasecmp(wso->output, name) == 0) { if (strcasecmp(wso->output, name) == 0) {
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
// Check if any other workspaces are using this name
if (find_container(&root_container, workspace_test, wso->workspace)) {
break;
}
ws_name = strdup(wso->workspace); ws_name = strdup(wso->workspace);
break; break;
} }
@ -206,6 +214,18 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
// NOTE: This is called from elsewhere without checking children length // NOTE: This is called from elsewhere without checking children length
// TODO move containers to other workspaces? // TODO move containers to other workspaces?
// for now just dont delete // for now just dont delete
// Do not destroy this if it's the last workspace on this output
swayc_t *output = workspace->parent;
while (output && output->type != C_OUTPUT) {
output = output->parent;
}
if (output) {
if (output->children->length == 1) {
return NULL;
}
}
if (workspace->children->length == 0) { if (workspace->children->length == 0) {
sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
swayc_t *parent = workspace->parent; swayc_t *parent = workspace->parent;

@ -16,7 +16,7 @@ static void update_focus(swayc_t *c) {
switch (c->type) { switch (c->type) {
case C_ROOT: return; case C_ROOT: return;
case C_OUTPUT: case C_OUTPUT:
wlc_output_focus(c->parent->handle); wlc_output_focus(c->handle);
break; break;
// switching workspaces // switching workspaces
case C_WORKSPACE: case C_WORKSPACE:

@ -174,6 +174,17 @@ void workspace_prev() {
} }
void workspace_switch(swayc_t *workspace) { void workspace_switch(swayc_t *workspace) {
if (!workspace) {
return;
}
sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name);
// Remove focus from current view
swayc_t *current = get_focused_view(&root_container);
if (current && current->type == C_VIEW) {
wlc_view_set_state(current->handle, WLC_BIT_ACTIVATED, false);
}
set_focused_container(workspace); set_focused_container(workspace);
active_workspace = workspace; active_workspace = workspace;
} }

Loading…
Cancel
Save