wmstatus: improve Sway forwards of xkb-lock-group
This commit is contained in:
parent
e83cfa3c15
commit
94bc8c251c
66
wmstatus.c
66
wmstatus.c
@ -2581,7 +2581,7 @@ action_xkb_lock_group (struct app_context *ctx, const struct strv *args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long group = strtol (args->vector[0], NULL, 10) - 1;
|
long group = strtol (args->vector[0], NULL, 10);
|
||||||
if (group < XkbGroup1Index || group > XkbGroup4Index)
|
if (group < XkbGroup1Index || group > XkbGroup4Index)
|
||||||
print_warning ("invalid XKB group index: %s", args->vector[0]);
|
print_warning ("invalid XKB group index: %s", args->vector[0]);
|
||||||
else
|
else
|
||||||
@ -3039,6 +3039,30 @@ sway_append_command_argument (struct str *out, const char *word)
|
|||||||
str_append_c (out, '\'');
|
str_append_c (out, '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
sway_shell_command_for_action (const struct strv *args)
|
||||||
|
{
|
||||||
|
// The i3/Sway quoting is properly fucked up,
|
||||||
|
// and its exec command forwards to `sh -c`.
|
||||||
|
struct str shell_command = str_make ();
|
||||||
|
if (strcmp (args->vector[0], "exec"))
|
||||||
|
{
|
||||||
|
// argv[0] would need realpath() applied on it.
|
||||||
|
shell_quote (PROGRAM_NAME, &shell_command);
|
||||||
|
str_append (&shell_command, " -- ");
|
||||||
|
shell_quote (args->vector[0], &shell_command);
|
||||||
|
str_append_c (&shell_command, ' ');
|
||||||
|
}
|
||||||
|
for (size_t i = 1; i < args->len; i++)
|
||||||
|
{
|
||||||
|
shell_quote (args->vector[i], &shell_command);
|
||||||
|
str_append_c (&shell_command, ' ');
|
||||||
|
}
|
||||||
|
if (shell_command.len)
|
||||||
|
shell_command.str[--shell_command.len] = 0;
|
||||||
|
return str_steal (&shell_command);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
sway_bindsym (const char *combination, const char *action)
|
sway_bindsym (const char *combination, const char *action)
|
||||||
{
|
{
|
||||||
@ -3063,25 +3087,6 @@ sway_bindsym (const char *combination, const char *action)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The i3/Sway quoting is properly fucked up,
|
|
||||||
// and its exec command forwards to `sh -c`.
|
|
||||||
struct str shell_command = str_make ();
|
|
||||||
if (strcmp (handler.name, "exec"))
|
|
||||||
{
|
|
||||||
// argv[0] would need realpath() applied on it.
|
|
||||||
shell_quote (PROGRAM_NAME, &shell_command);
|
|
||||||
str_append (&shell_command, " -- ");
|
|
||||||
shell_quote (handler.name, &shell_command);
|
|
||||||
str_append_c (&shell_command, ' ');
|
|
||||||
}
|
|
||||||
for (size_t i = 1; i < args.len; i++)
|
|
||||||
{
|
|
||||||
shell_quote (args.vector[i], &shell_command);
|
|
||||||
str_append_c (&shell_command, ' ');
|
|
||||||
}
|
|
||||||
if (shell_command.len)
|
|
||||||
shell_command.str[--shell_command.len] = 0;
|
|
||||||
|
|
||||||
// This command name may not be quoted.
|
// This command name may not be quoted.
|
||||||
// Note that i3-msg doesn't accept bindsym at all, only swaymsg does.
|
// Note that i3-msg doesn't accept bindsym at all, only swaymsg does.
|
||||||
struct str sway_command = str_make ();
|
struct str sway_command = str_make ();
|
||||||
@ -3089,9 +3094,24 @@ sway_bindsym (const char *combination, const char *action)
|
|||||||
char *recombined = strv_join (&keys, "+");
|
char *recombined = strv_join (&keys, "+");
|
||||||
sway_append_command_argument (&sway_command, recombined);
|
sway_append_command_argument (&sway_command, recombined);
|
||||||
free (recombined);
|
free (recombined);
|
||||||
sway_append_command_argument (&sway_command, "exec");
|
|
||||||
sway_append_command_argument (&sway_command, shell_command.str);
|
if (handler.handler == action_xkb_lock_group)
|
||||||
str_free (&shell_command);
|
{
|
||||||
|
// This should also switch the XWayland layout,
|
||||||
|
// though it has been observed to not take effect immediately.
|
||||||
|
sway_append_command_argument (&sway_command, "input");
|
||||||
|
sway_append_command_argument (&sway_command, "type:keyboard");
|
||||||
|
sway_append_command_argument (&sway_command, "xkb_switch_layout");
|
||||||
|
for (size_t i = 1; i < args.len; i++)
|
||||||
|
sway_append_command_argument (&sway_command, args.vector[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sway_append_command_argument (&sway_command, "exec");
|
||||||
|
char *shell_command = sway_shell_command_for_action (&args);
|
||||||
|
sway_append_command_argument (&sway_command, shell_command);
|
||||||
|
free (shell_command);
|
||||||
|
}
|
||||||
|
|
||||||
struct strv argv = strv_make ();
|
struct strv argv = strv_make ();
|
||||||
strv_append (&argv, "swaymsg");
|
strv_append (&argv, "swaymsg");
|
||||||
|
@ -16,10 +16,10 @@ keys = {
|
|||||||
"XF86AudioPrev" = "mpd previous"
|
"XF86AudioPrev" = "mpd previous"
|
||||||
"XF86AudioNext" = "mpd next"
|
"XF86AudioNext" = "mpd next"
|
||||||
|
|
||||||
"Mod4 F1" = "xkb-lock-group 1"
|
"Mod4 F1" = "xkb-lock-group 0"
|
||||||
"Mod4 F2" = "xkb-lock-group 2"
|
"Mod4 F2" = "xkb-lock-group 1"
|
||||||
"Mod4 F3" = "xkb-lock-group 3"
|
"Mod4 F3" = "xkb-lock-group 2"
|
||||||
"Mod4 F4" = "xkb-lock-group 4"
|
"Mod4 F4" = "xkb-lock-group 3"
|
||||||
|
|
||||||
"Mod4 Control F1" = "exec input-switch vga 1"
|
"Mod4 Control F1" = "exec input-switch vga 1"
|
||||||
"Mod4 Control Shift F1" = "exec input-switch vga 2"
|
"Mod4 Control Shift F1" = "exec input-switch vga 2"
|
||||||
|
Loading…
Reference in New Issue
Block a user