Fix assigning workspaces to outputs

It's possible to assign workspaces to certain outputs using the command:

    workspace <name> output <output>

However, this did not work in some cases where the workspace was
assigned before the given output was made available to sway.

This patch fixes those cases.
master
Mikkel Oscar Lyderik 9 years ago
parent 79bfd620d6
commit 8ddafeeaae

@ -7,7 +7,7 @@
extern char *prev_workspace_name; extern char *prev_workspace_name;
char *workspace_next_name(void); char *workspace_next_name(const char *output_name);
swayc_t *workspace_create(const char*); swayc_t *workspace_create(const char*);
swayc_t *workspace_by_name(const char*); swayc_t *workspace_by_name(const char*);
swayc_t *workspace_by_number(const char*); swayc_t *workspace_by_number(const char*);

@ -143,7 +143,7 @@ swayc_t *new_output(wlc_handle handle) {
} }
} }
if (!ws_name) { if (!ws_name) {
ws_name = workspace_next_name(); ws_name = workspace_next_name(output->name);
} }
// create and initilize default workspace // create and initilize default workspace

@ -364,7 +364,7 @@ void move_workspace_to(swayc_t* workspace, swayc_t* destination) {
// make sure source output has a workspace // make sure source output has a workspace
if (src_op->children->length == 0) { if (src_op->children->length == 0) {
char *ws_name = workspace_next_name(); char *ws_name = workspace_next_name(src_op->name);
swayc_t *ws = new_workspace(src_op, ws_name); swayc_t *ws = new_workspace(src_op, ws_name);
ws->is_focused = true; ws->is_focused = true;
free(ws_name); free(ws_name);

@ -25,8 +25,22 @@ struct workspace_by_number_data {
const char *name; const char *name;
}; };
char *workspace_next_name(void) { static bool workspace_valid_on_output(const char *output_name, const char *ws_name) {
sway_log(L_DEBUG, "Workspace: Generating new name"); int i;
for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
if (strcasecmp(wso->workspace, ws_name) == 0) {
if (strcasecmp(wso->output, output_name) != 0) {
return false;
}
}
}
return true;
}
char *workspace_next_name(const char *output_name) {
sway_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", output_name);
int i; int i;
int l = 1; int l = 1;
// Scan all workspace bindings to find the next available workspace name, // Scan all workspace bindings to find the next available workspace name,
@ -73,6 +87,14 @@ char *workspace_next_name(void) {
free(_target); free(_target);
continue; continue;
} }
// make sure that the workspace can appear on the given
// output
if (!workspace_valid_on_output(output_name, _target)) {
free(_target);
continue;
}
if (binding->order < order) { if (binding->order < order) {
order = binding->order; order = binding->order;
target = _target; target = _target;

Loading…
Cancel
Save