Workspaces: allow switching by moving with Workspaces [left|right|down|up]

* -i to dump the layout
* Idea taken from workspacectl

Change-Id: I8d0c4abdffc63db14f3a4ecd590439fbbfe38ce4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/11127
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
Jérôme Duval
2026-06-16 04:57:27 +00:00
parent 528bb58299
commit 31c245ae13
+31 -22
View File
@@ -1018,7 +1018,7 @@ WorkspacesApp::AboutRequested()
void
WorkspacesApp::Usage(const char *programName)
{
printf(B_TRANSLATE("Usage: %s [options] [workspace]\n"
printf(B_TRANSLATE("Usage: %s [options] [workspace|movement]\n"
"where \"options\" are:\n"
" --notitle\t\ttitle bar removed, border and resize kept\n"
" --noborder\t\ttitle, border, and resize removed\n"
@@ -1029,8 +1029,10 @@ WorkspacesApp::Usage(const char *programName)
" --autoraise\t\tauto-raise the workspace window when it's at the "
"screen edge\n"
" --help\t\tdisplay this help and exit\n"
"and \"workspace\" is the number of the Workspace to which to switch "
"(0-31)\n"),
" -i\t\t\tdisplay workspace layout and exit\n"
"\"workspace\" is the number of the Workspace to which to switch (0-31)\n"
"and \"movement\" is the move to find the Workspace to which to switch "
"(+|-left|right|top|down)\n"),
programName);
// quit only if we aren't running already
@@ -1063,29 +1065,36 @@ WorkspacesApp::ArgvReceived(int32 argc, char **argv)
Usage(programName);
}
} else if (isdigit(*argv[i])) {
// check for a numeric arg, if not already given
activate_workspace(atoi(argv[i]));
} else {
uint32 columns, rows;
BPrivate::get_workspaces_layout(&columns, &rows);
if (isdigit(*argv[i])) {
// check for a numeric arg, if not already given
activate_workspace(atoi(argv[i]));
} else if (!strcmp(argv[i], "-i")) {
printf("layout (columns,rows): %" B_PRId32 "x%" B_PRId32 "\n", columns, rows);
} else if (!strcmp(argv[i], "-")) {
activate_workspace(current_workspace() - 1);
} else if (!strcmp(argv[i], "+")) {
activate_workspace(current_workspace() + 1);
} else if (!strcmp(argv[i], "up")) {
activate_workspace((current_workspace() - columns) % (columns * rows));
} else if (!strcmp(argv[i], "down")) {
activate_workspace((current_workspace() + columns) % (columns * rows));
} else if (!strcmp(argv[i], "left")) {
activate_workspace(
current_workspace() / rows * rows + ((current_workspace() - 1) % rows));
} else if (!strcmp(argv[i], "right")) {
activate_workspace(
current_workspace() / rows * rows + ((current_workspace() + 1) % rows));
} else {
// some unknown arguments were specified
fprintf(stderr, B_TRANSLATE("Invalid argument: %s\n"), argv[i]);
}
// if the app is running, don't quit
// but if it isn't, cancel the complete run, so it doesn't
// open any window
if (IsLaunching())
Quit();
} else if (!strcmp(argv[i], "-")) {
activate_workspace(current_workspace() - 1);
if (IsLaunching())
Quit();
} else if (!strcmp(argv[i], "+")) {
activate_workspace(current_workspace() + 1);
if (IsLaunching())
Quit();
} else {
// some unknown arguments were specified
fprintf(stderr, B_TRANSLATE("Invalid argument: %s\n"), argv[i]);
if (IsLaunching())
Quit();
}