Skip to content

Commit

Permalink
- add --relative flag to set_desktop.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed May 30, 2011
1 parent c246171 commit 1ebacea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
29 changes: 27 additions & 2 deletions cmd_set_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@
int cmd_set_desktop(context_t *context) {
char *cmd = *context->argv;
long desktop;
int relative = False;

int c;
typedef enum {
opt_unused, opt_help, opt_relative
} optlist_t;

static struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ "help", no_argument, NULL, opt_help },
{ "relative", no_argument, NULL, opt_relative },
{ 0, 0, 0, 0 },
};
static const char *usage = "Usage: %s desktop\n";
static const char *usage =
"Usage: %s desktop\n"
"--relative - Move relative to the current desktop. Negative values OK\n";
int option_index;

while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
case opt_help:
printf(usage, cmd);
consume_args(context, context->argc);
return EXIT_SUCCESS;
break;
case opt_relative:
relative = True;
break;
default:
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
Expand All @@ -36,6 +48,19 @@ int cmd_set_desktop(context_t *context) {
desktop = strtol(context->argv[0], NULL, 0);

consume_args(context, 1);

if (relative == True) {
long cur_desktop = 0, ndesktops = 0;
xdo_get_current_desktop(context->xdo, &cur_desktop);
xdo_get_number_of_desktops(context->xdo, &ndesktops);

desktop = (desktop + cur_desktop) % ndesktops;

/* negative mod doesn't result in a positive number. Fix that. */
if (desktop < 0)
desktop += ndesktops;
}

return xdo_set_current_desktop(context->xdo, desktop);
}

11 changes: 10 additions & 1 deletion xdotool.pod
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,19 @@ the screen size.
For example, if your screen is 1280x800, you can move to the 2nd workspace by doing:
xdotool set_desktop_viewport 1280 0

=item B<set_desktop> I<desktop_number>
=item B<set_desktop> I<[options]> I<desktop_number>

Change the current view to the specified desktop.

=over

=item B<--relative>

Use relative movements instead of absolute. This lets you move relative to the
current desktop.

=back

=item B<get_desktop>

Output the current desktop in view.
Expand Down

0 comments on commit 1ebacea

Please sign in to comment.