File wlrctl-1596702887.6cfacab.obscpio of Package wlrctl
07070100000000000081A4000003E800000064000000015F2BC0A70000042D000000000000000000000000000000000000002200000000wlrctl-1596702887.6cfacab/LICENSEMIT License
Copyright (c) 2020 Ronan Pigott
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
07070100000001000081A4000003E800000064000000015F2BC0A7000003D5000000000000000000000000000000000000002400000000wlrctl-1596702887.6cfacab/README.md# wlrctl
wlrctl is a command line utility for miscellaneous wlroots Wayland extensions.
At this time, wlrctl supports the foreign-toplevel-mangement (window/toplevel command),
virtual-keyboard (keyboard command), and virtual-pointer (pointer command) protocols.
## Installation
There is an AUR package for wlrctl [here][aur-wlrctl].
And an openSUSE package [here][os-wlrctl].
## Features and Examples
wlrctl is still experimental, and has just a few basic features.
Check the man page wlrctl(1) for full details.
Some example uses are:
$ wlrctl keyboard type 'Hello, world!'
... to type some text using a virtual keyboard.
$ wlrctl pointer move 50 -70
... to move the cursor 50 pixels right and 70 pixels up.
$ wlrctl window focus firefox || swaymsg exec firefox
... to focus firefox if it is running, otherwise start firefox.
[aur-wlrctl]: https://aur.archlinux.org/packages/wlrctl
[os-wlrctl]: https://build.opensuse.org/package/show/X11:Wayland/wlrctl
07070100000002000081A4000003E800000064000000015F2BC0A7000016AD000000000000000000000000000000000000002D00000000wlrctl-1596702887.6cfacab/ascii_raw_keymap.cconst char keymap_ascii_raw[] =
"xkb_keymap {\n"
"xkb_keycodes \"ascii\" {\n"
" minimum = 8;\n"
" maximum = 127;\n"
"\n"
" <BKSP> = 8;\n"
" <TAB> = 9;\n"
" <RTRN> = 10;\n"
" <ESC> = 27;\n"
" <SPCE> = 32;\n"
" <EXCL> = 33;\n"
" <QDBL> = 34;\n"
" <HASH> = 35;\n"
" <DOLL> = 36;\n"
" <PCNT> = 37;\n"
" <AMP> = 38;\n"
" <APOS> = 39;\n"
" <LPAR> = 40;\n"
" <RPAR> = 41;\n"
" <STAR> = 42;\n"
" <PLUS> = 43;\n"
" <COMM> = 44;\n"
" <MIN> = 45;\n"
" <PRD> = 46;\n"
" <FWSL> = 47;\n"
" <NUM0> = 48;\n"
" <NUM1> = 49;\n"
" <NUM2> = 50;\n"
" <NUM3> = 51;\n"
" <NUM4> = 52;\n"
" <NUM5> = 53;\n"
" <NUM6> = 54;\n"
" <NUM7> = 55;\n"
" <NUM8> = 56;\n"
" <NUM9> = 57;\n"
" <COLN> = 58;\n"
" <SCLN> = 59;\n"
" <LESS> = 60;\n"
" <EQL> = 61;\n"
" <GRTR> = 62;\n"
" <QUES> = 63;\n"
" <ATSN> = 64;\n"
" <KEYA> = 65;\n"
" <KEYB> = 66;\n"
" <KEYC> = 67;\n"
" <KEYD> = 68;\n"
" <KEYE> = 69;\n"
" <KEYF> = 70;\n"
" <KEYG> = 71;\n"
" <KEYH> = 72;\n"
" <KEYI> = 73;\n"
" <KEYJ> = 74;\n"
" <KEYK> = 75;\n"
" <KEYL> = 76;\n"
" <KEYM> = 77;\n"
" <KEYN> = 78;\n"
" <KEYO> = 79;\n"
" <KEYP> = 80;\n"
" <KEYQ> = 81;\n"
" <KEYR> = 82;\n"
" <KEYS> = 83;\n"
" <KEYT> = 84;\n"
" <KEYU> = 85;\n"
" <KEYV> = 86;\n"
" <KEYW> = 87;\n"
" <KEYX> = 88;\n"
" <KEYY> = 89;\n"
" <KEYZ> = 90;\n"
" <LBRC> = 91;\n"
" <BKSL> = 92;\n"
" <RBRC> = 93;\n"
" <CRCM> = 94;\n"
" <UNDR> = 95;\n"
" <GRV> = 96;\n"
" <KEYa> = 97;\n"
" <KEYb> = 98;\n"
" <KEYc> = 99;\n"
" <KEYd> = 100;\n"
" <KEYe> = 101;\n"
" <KEYf> = 102;\n"
" <KEYg> = 103;\n"
" <KEYh> = 104;\n"
" <KEYi> = 105;\n"
" <KEYj> = 106;\n"
" <KEYk> = 107;\n"
" <KEYl> = 108;\n"
" <KEYm> = 109;\n"
" <KEYn> = 110;\n"
" <KEYo> = 111;\n"
" <KEYp> = 112;\n"
" <KEYq> = 113;\n"
" <KEYr> = 114;\n"
" <KEYs> = 115;\n"
" <KEYt> = 116;\n"
" <KEYu> = 117;\n"
" <KEYv> = 118;\n"
" <KEYw> = 119;\n"
" <KEYx> = 120;\n"
" <KEYy> = 121;\n"
" <KEYz> = 122;\n"
" <LBRA> = 123;\n"
" <BAR> = 124;\n"
" <RBRA> = 125;\n"
" <TLDE> = 126;\n"
"};\n"
"\n"
"xkb_types \"flat\" {\n"
" virtual_modifiers NumLock;\n"
"\n"
" type \"ONE_LEVEL\" {\n"
" modifiers =none;\n"
" level_name[1] = \"Any\";\n"
" };\n"
" type \"TWO_LEVEL\" {\n"
" modifiers = Shift;\n"
" map[Shift] = Level2;\n"
" level_name[Level1] = \"Base\";\n"
" level_name[Level2] = \"Shift\";\n"
" };\n"
" type \"ALPHABETIC\" {\n"
" modifiers = Shift+Lock;\n"
" map[Shift] = Level2;\n"
" map[Lock] = Level2;\n"
" level_name[Level1] = \"Base\";\n"
" level_name[Level2] = \"Caps\";\n"
" };\n"
" type \"KEYPAD\" {\n"
" modifiers = Shift+NumLock;\n"
" map[None] = Level1;\n"
" map[Shift] = Level2;\n"
" map[NumLock] = Level2;\n"
" map[Shift+NumLock] = Level1;\n"
" level_name[Level1] = \"Base\";\n"
" level_name[Level2] = \"Number\";\n"
" };\n"
"};\n"
"\n"
"xkb_compatibility \"basic\" {\n"
" virtual_modifiers NumLock;\n"
"\n"
" interpret.useModMapMods = AnyLevel;\n"
" interpret.repeat = False;\n"
" interpret.locking = False;\n"
" interpret Shift_Lock+AnyOf(Shift+Lock) {\n"
" action = LockMods(modifiers=Shift);\n"
" };\n"
"};\n"
"\n"
"xkb_symbols \"ascii\" {\n"
" name[Group1]=\"ASCII RAW\";\n"
"\n"
" key <BKSP> {[ BackSpace ]};\n"
" key <TAB> {[ Tab ]};\n"
" key <RTRN> {[ Return ]};\n"
" key <ESC> {[ Escape ]};\n"
" key <SPCE> {[ space ]};\n"
" key <EXCL> {[ exclam ]};\n"
" key <QDBL> {[ quotedbl ]};\n"
" key <HASH> {[ numbersign ]};\n"
" key <DOLL> {[ dollar ]};\n"
" key <PCNT> {[ percent ]};\n"
" key <AMP> {[ ampersand ]};\n"
" key <APOS> {[ apostrophe ]};\n"
" key <LPAR> {[ parenleft ]};\n"
" key <RPAR> {[ parenright ]};\n"
" key <STAR> {[ asterisk ]};\n"
" key <PLUS> {[ plus ]};\n"
" key <COMM> {[ comma ]};\n"
" key <MIN> {[ minus ]};\n"
" key <PRD> {[ period ]};\n"
" key <FWSL> {[ slash ]};\n"
" key <NUM0> {[ 0 ]};\n"
" key <NUM1> {[ 1 ]};\n"
" key <NUM2> {[ 2 ]};\n"
" key <NUM3> {[ 3 ]};\n"
" key <NUM4> {[ 4 ]};\n"
" key <NUM5> {[ 5 ]};\n"
" key <NUM6> {[ 6 ]};\n"
" key <NUM7> {[ 7 ]};\n"
" key <NUM8> {[ 8 ]};\n"
" key <NUM9> {[ 9 ]};\n"
" key <COLN> {[ colon ]};\n"
" key <SCLN> {[ semicolon ]};\n"
" key <LESS> {[ less ]};\n"
" key <EQL> {[ equal ]};\n"
" key <GRTR> {[ greater ]};\n"
" key <QUES> {[ question ]};\n"
" key <ATSN> {[ at ]};\n"
" key <KEYA> {[ A ]};\n"
" key <KEYB> {[ B ]};\n"
" key <KEYC> {[ C ]};\n"
" key <KEYD> {[ D ]};\n"
" key <KEYE> {[ E ]};\n"
" key <KEYF> {[ F ]};\n"
" key <KEYG> {[ G ]};\n"
" key <KEYH> {[ H ]};\n"
" key <KEYI> {[ I ]};\n"
" key <KEYJ> {[ J ]};\n"
" key <KEYK> {[ K ]};\n"
" key <KEYL> {[ L ]};\n"
" key <KEYM> {[ M ]};\n"
" key <KEYN> {[ N ]};\n"
" key <KEYO> {[ O ]};\n"
" key <KEYP> {[ P ]};\n"
" key <KEYQ> {[ Q ]};\n"
" key <KEYR> {[ R ]};\n"
" key <KEYS> {[ S ]};\n"
" key <KEYT> {[ T ]};\n"
" key <KEYU> {[ U ]};\n"
" key <KEYV> {[ V ]};\n"
" key <KEYW> {[ W ]};\n"
" key <KEYX> {[ X ]};\n"
" key <KEYY> {[ Y ]};\n"
" key <KEYZ> {[ Z ]};\n"
" key <LBRC> {[ braceleft ]};\n"
" key <BKSL> {[ backslash ]};\n"
" key <RBRC> {[ braceright ]};\n"
" key <CRCM> {[ asciicircum ]};\n"
" key <UNDR> {[ underscore ]};\n"
" key <GRV> {[ grave ]};\n"
" key <KEYa> {[ a ]};\n"
" key <KEYb> {[ b ]};\n"
" key <KEYc> {[ c ]};\n"
" key <KEYd> {[ d ]};\n"
" key <KEYe> {[ e ]};\n"
" key <KEYf> {[ f ]};\n"
" key <KEYg> {[ g ]};\n"
" key <KEYh> {[ h ]};\n"
" key <KEYi> {[ i ]};\n"
" key <KEYj> {[ j ]};\n"
" key <KEYk> {[ k ]};\n"
" key <KEYl> {[ l ]};\n"
" key <KEYm> {[ m ]};\n"
" key <KEYn> {[ n ]};\n"
" key <KEYo> {[ o ]};\n"
" key <KEYp> {[ p ]};\n"
" key <KEYq> {[ q ]};\n"
" key <KEYr> {[ r ]};\n"
" key <KEYs> {[ s ]};\n"
" key <KEYt> {[ t ]};\n"
" key <KEYu> {[ u ]};\n"
" key <KEYv> {[ v ]};\n"
" key <KEYw> {[ w ]};\n"
" key <KEYx> {[ x ]};\n"
" key <KEYy> {[ y ]};\n"
" key <KEYz> {[ z ]};\n"
" key <LBRA> {[ bracketleft ]};\n"
" key <BAR> {[ bar ]};\n"
" key <RBRA> {[ bracketright ]};\n"
" key <TLDE> {[ asciitilde ]};\n"
"};\n"
"};\n";
07070100000003000041ED000003E800000064000000035F2BC0A700000000000000000000000000000000000000000000002600000000wlrctl-1596702887.6cfacab/completions07070100000004000041ED000003E800000064000000025F2BC0A700000000000000000000000000000000000000000000002A00000000wlrctl-1596702887.6cfacab/completions/zsh07070100000005000081A4000003E800000064000000015F2BC0A70000065D000000000000000000000000000000000000003200000000wlrctl-1596702887.6cfacab/completions/zsh/_wlrctl#compdef wlrctl
local cmd="$0"
typeset -A opt_args
__wlrctl() {
"$cmd" "$@"
}
local -a wlrcmd_keyboard
_regex_words action 'keyboard action' \
'type:Type an ascii string'
wlrcmd_keyboard=("$reply[@]")
local -a pointer_button
_regex_words button 'pointer button' 'left' 'right' 'middle' \
'extra' 'side' 'forward' 'back'
pointer_button=("$reply[@]")
local -a wlrcmd_pointer
_regex_words action 'pointer action' \
'click:Click a pointer button:$pointer_button' \
'move:Move the cursor' \
'scroll:Imitate a swipe scroll'
wlrcmd_pointer=("$reply[@]")
(( $+functions[_wlr_toplevel_attr] )) || _wlr_toplevel_attr() {
local -a windows matchspecs
windows=(${(@f)"$(__wlrctl toplevel list)"})
matchspecs=( app_id:${^windows%%: *} title:${^windows#*: } )
matchspecs+=( state:{{un,}minimized,{un,}maximized,{in,}active,{un,}fullscreen} )
_multi_parts ':' matchspecs
}
local -a wlrcmd_toplevel_attr=(/$'[^\0]#\0'/ ':_wlr_toplevel_attr')
local -a wlrcmd_toplevel
_regex_words action 'toplevel action' 'maximize' 'minimize' 'focus' \
'activate' 'fullscreen' 'close' 'list' 'find' 'wait' 'waitfor'
wlrcmd_toplevel=( "$reply[@]" "$wlrcmd_toplevel_attr[@]" )
local -a wlrcmd
_regex_words commands 'wlr command' \
'keyboard:Control a virtual keyboard:$wlrcmd_keyboard' \
'pointer:Control a virtual pointer:$wlrcmd_pointer' \
{window,toplevel}':Manage windows:$wlrcmd_toplevel'
wlrcmd=( /$'[^\0]#\0'/ "$reply[@]" )
_regex_arguments _wlrcmd "$wlrcmd[@]"
_arguments -S \
'(-h --help)'{-h,--help}'[Show a help message and exit]' \
'(-v --version)'{-v,--version}'[Show a version number and exit]' \
'*::wlr command:= _wlrcmd'
07070100000006000041ED000003E800000064000000025F2BC0A700000000000000000000000000000000000000000000002200000000wlrctl-1596702887.6cfacab/include07070100000007000081A4000003E800000064000000015F2BC0A700000228000000000000000000000000000000000000002B00000000wlrctl-1596702887.6cfacab/include/common.h#ifndef WLRCTL_COMMON_H
#define WLRCTL_COMMON_H
#include <stdbool.h>
enum wlrctl_command {
WLRCTL_COMMAND_UNSPEC = 0,
WLRCTL_COMMAND_KEYBOARD,
WLRCTL_COMMAND_POINTER,
WLRCTL_COMMAND_TOPLEVEL,
};
struct wlrctl {
// Globals
struct wl_display *display;
struct wl_registry *registry;
struct wl_seat *seat;
struct zwp_virtual_keyboard_manager_v1 *vkbd_mgr;
struct zwlr_foreign_toplevel_manager_v1 *ftl_mgr;
struct zwlr_virtual_pointer_manager_v1 *vp_mgr;
// State
bool running, failed;
enum wlrctl_command cmd_type;
void *cmd;
};
#endif
07070100000008000081A4000003E800000064000000015F2BC0A700000225000000000000000000000000000000000000002D00000000wlrctl-1596702887.6cfacab/include/keyboard.h#ifndef WLRCTL_DEV_KEYBOARD_H
#define WLRCTL_DEV_KEYBOARD_H
enum keyboard_action {
KEYBOARD_ACTION_UNSPEC = 0,
KEYBOARD_ACTION_TYPE,
};
struct wlrctl_keyboard_command {
enum keyboard_action action;
char *text;
struct zwp_virtual_keyboard_v1 *device;
struct xkb_context *xkb_context;
struct {
uint32_t format;
uint32_t size;
int fd;
} keymap;
struct wlrctl *state;
};
void prepare_keyboard(struct wlrctl *state, int argc, char *argv[]);
void run_keyboard(struct wlrctl *state);
void destroy_keyboard(struct wlrctl *state);
#endif
07070100000009000081A4000003E800000064000000015F2BC0A700000200000000000000000000000000000000000000002C00000000wlrctl-1596702887.6cfacab/include/pointer.h#ifndef WLRCTL_DEV_POINTER_H
#define WLRCTL_DEV_POINTER_H
enum pointer_action {
POINTER_ACTION_UNSPEC = 0,
POINTER_ACTION_CLICK,
POINTER_ACTION_MOTION,
POINTER_ACTION_SCROLL,
};
struct wlrctl_pointer_command {
enum pointer_action action;
uint32_t button;
wl_fixed_t dx, dy;
struct zwlr_virtual_pointer_v1 *device;
struct wlrctl *state;
};
void prepare_pointer(struct wlrctl *state, int argc, char *argv[]);
void run_pointer(struct wlrctl *state);
void destroy_pointer(struct wlrctl *state);
#endif
0707010000000A000081A4000003E800000064000000015F2BC0A70000055A000000000000000000000000000000000000002D00000000wlrctl-1596702887.6cfacab/include/toplevel.h#ifndef WLRCTL_TOPLEVEL_H
#define WLRCTL_TOPLEVEL_H
enum toplevel_attr {
TOPLEVEL_ATTR_UNSPEC = 0,
TOPLEVEL_ATTR_APPID = 1<<1,
TOPLEVEL_ATTR_TITLE = 1<<2,
TOPLEVEL_ATTR_MAXIMIZED = 1<<3,
TOPLEVEL_ATTR_MINIMIZED = 1<<4,
TOPLEVEL_ATTR_ACTIVATED = 1<<5,
TOPLEVEL_ATTR_FULLSCREEN = 1<<6,
};
enum toplevel_action {
TOPLEVEL_ACTION_UNSPEC = 0,
TOPLEVEL_ACTION_ACTIVATE,
TOPLEVEL_ACTION_CLOSE,
TOPLEVEL_ACTION_FIND,
TOPLEVEL_ACTION_FULLSCREEN,
TOPLEVEL_ACTION_LIST,
TOPLEVEL_ACTION_MAXIMIZE,
TOPLEVEL_ACTION_MINIMIZE,
TOPLEVEL_ACTION_WAIT,
TOPLEVEL_ACTION_WAITFOR,
};
struct toplevel_matchspec {
unsigned int attrs;
// toplevel attr
struct wl_array app_ids;
struct wl_array titles;
// toplevel state
bool maximized;
bool minimized;
bool activated;
bool fullscreen;
};
struct wlrctl_toplevel_command {
enum toplevel_action action;
struct toplevel_matchspec matchspec;
struct wl_list toplevels;
bool any;
bool complete;
int waiting;
struct wlrctl *state;
};
struct toplevel_data {
char *app_id;
char *title;
struct wl_array state;
struct wl_list link;
struct wlrctl_toplevel_command *cmd;
bool matched, done;
};
void prepare_toplevel(struct wlrctl *state, int argc, char **argv);
void run_toplevel(struct wlrctl *state);
void stop_toplevel(struct wlrctl *state);
void destroy_toplevel(struct wlrctl *state);
#endif
0707010000000B000081A4000003E800000064000000015F2BC0A7000000D8000000000000000000000000000000000000002900000000wlrctl-1596702887.6cfacab/include/util.h#ifndef WLRCTL_UTIL_H
#define WLRCTL_UTIL_H
struct token {
const char *name;
int value;
};
int matchtok(const struct token tokens[], const char *name);
int timestamp();
void die(const char *fmt, ...);
#endif
0707010000000C000081A4000003E800000064000000015F2BC0A700000E2D000000000000000000000000000000000000002500000000wlrctl-1596702887.6cfacab/keyboard.c#define _GNU_SOURCE
#include <assert.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include "common.h"
#include "keyboard.h"
#include "util.h"
#include "virtual-keyboard-unstable-v1-client-protocol.h"
extern const char keymap_ascii_raw[];
static void
get_keymap(struct wlrctl_keyboard_command *cmd)
{
int size = strlen(keymap_ascii_raw) + 1;
int fd = memfd_create("keymap", 0);
if(ftruncate(fd, size) < 0) {
die("Could not allocate shm for keymap\n");
};
void *keymap_data =
mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
strcpy(keymap_data, keymap_ascii_raw);
munmap(keymap_data, size);
cmd->keymap.format = WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1;
cmd->keymap.fd = fd;
cmd->keymap.size = size;
}
static void
send_key(struct zwp_virtual_keyboard_v1 *kbd, char c)
{
zwp_virtual_keyboard_v1_key(kbd, timestamp(), c - 8, WL_KEYBOARD_KEY_STATE_PRESSED);
zwp_virtual_keyboard_v1_key(kbd, timestamp(), c - 8, WL_KEYBOARD_KEY_STATE_RELEASED);
}
static void
keyboard_type(struct wlrctl_keyboard_command *cmd, const char *text)
{
int len = strlen(text);
for (int i = 0; i < len; i++) {
send_key(cmd->device, text[i]);
}
}
static void
complete_keyboard(void *data, struct wl_callback *callback, uint32_t serial)
{
struct wlrctl *state = data;
wl_callback_destroy(callback);
state->running = false;
destroy_keyboard(state);
}
static struct wl_callback_listener completed_listener = {
.done = complete_keyboard
};
static enum keyboard_action
parse_action(const char *action)
{
static const struct token actions[] = {
{"type", KEYBOARD_ACTION_TYPE},
{NULL, KEYBOARD_ACTION_UNSPEC}
};
return matchtok(actions, action);
}
static bool
is_ascii(const char str[])
{
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] < 0) {
return false;
}
}
return true;
}
void
prepare_keyboard(struct wlrctl *state, int argc, char *argv[])
{
struct wlrctl_keyboard_command *cmd =
calloc(1, sizeof (struct wlrctl_keyboard_command));
assert(cmd);
if (argc == 0) {
die("Missing keyboard action\n");
}
char *action = argv[0];
cmd->action = parse_action(action);
switch (cmd->action) {
case KEYBOARD_ACTION_TYPE:
if (argc < 2) {
die("Missing text to type!\n");
} else if (argc == 2) {
if (is_ascii(argv[1])) {
cmd->text = strdup(argv[1]);
} else {
die("Only ascii strings are currently supported\n");
}
} else {
die("Extra argument: '%s'\n", argv[2]);
}
break;
case KEYBOARD_ACTION_UNSPEC:
die("Unknown keyboard action: '%s'\n", action);
break;
}
cmd->state = state;
state->cmd = cmd;
}
void
run_keyboard(struct wlrctl *state)
{
struct wlrctl_keyboard_command *cmd = state->cmd;
cmd->device =
zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(
state->vkbd_mgr, state->seat
);
cmd->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
get_keymap(cmd);
zwp_virtual_keyboard_v1_keymap(cmd->device,
cmd->keymap.format, cmd->keymap.fd, cmd->keymap.size
);
close(cmd->keymap.fd);
switch (cmd->action) {
case KEYBOARD_ACTION_TYPE:
zwp_virtual_keyboard_v1_modifiers(cmd->device, 0, 0, 0, 0);
keyboard_type(cmd, cmd->text);
break;
default:
break;
}
struct wl_callback *callback = wl_display_sync(state->display);
wl_callback_add_listener(callback, &completed_listener, state);
}
void destroy_keyboard(struct wlrctl *state)
{
struct wlrctl_keyboard_command *cmd = state->cmd;
zwp_virtual_keyboard_v1_destroy(cmd->device);
free(cmd);
}
0707010000000D000081A4000003E800000064000000015F2BC0A700001298000000000000000000000000000000000000002100000000wlrctl-1596702887.6cfacab/main.c#include <assert.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <xkbcommon/xkbcommon.h>
#include <wayland-client.h>
#include "common.h"
#include "keyboard.h"
#include "pointer.h"
#include "toplevel.h"
#include "util.h"
#include "virtual-keyboard-unstable-v1-client-protocol.h"
#include "wlr-virtual-pointer-unstable-v1-client-protocol.h"
#include "wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"
static void noop() {}
static void
registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version)
{
struct wlrctl *state = data;
// Bind wl_seat
if (strcmp(interface, wl_seat_interface.name) == 0) {
state->seat = wl_registry_bind(
registry, name, &wl_seat_interface, 7
);
}
// Bind zwp_virtual_keyboard_manager_v1
if (strcmp(interface, zwp_virtual_keyboard_manager_v1_interface.name) == 0) {
if (state->cmd_type == WLRCTL_COMMAND_KEYBOARD) {
state->vkbd_mgr = wl_registry_bind(
registry, name, &zwp_virtual_keyboard_manager_v1_interface, 1
);
}
}
// Bind zwlr_virtual_pointer_manager_v1
if (strcmp(interface, zwlr_virtual_pointer_manager_v1_interface.name) == 0) {
if (state->cmd_type == WLRCTL_COMMAND_POINTER) {
state->vp_mgr = wl_registry_bind(
registry, name, &zwlr_virtual_pointer_manager_v1_interface, 2
);
}
}
// Bind zwlr_foreign_toplevel_manager_v1
if (strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0) {
if (state->cmd_type == WLRCTL_COMMAND_TOPLEVEL) {
state->ftl_mgr = wl_registry_bind(
registry, name, &zwlr_foreign_toplevel_manager_v1_interface, 2
);
}
}
}
static const struct wl_registry_listener
wl_registry_listener = {
.global = registry_handle_global,
.global_remove = noop,
};
static bool
prepare_command(struct wlrctl *state, int argc, char *argv[])
{
char *command = argv[0];
static const struct token commands[] = {
{"keyboard", WLRCTL_COMMAND_KEYBOARD},
{"pointer", WLRCTL_COMMAND_POINTER },
{"toplevel", WLRCTL_COMMAND_TOPLEVEL},
{"window", WLRCTL_COMMAND_TOPLEVEL},
{NULL, WLRCTL_COMMAND_UNSPEC},
};
state->cmd_type = matchtok(commands, command);
switch (state->cmd_type) {
case WLRCTL_COMMAND_KEYBOARD:
prepare_keyboard(state, argc - 1, argv + 1);
break;
case WLRCTL_COMMAND_POINTER:
prepare_pointer(state, argc - 1, argv + 1);
break;
case WLRCTL_COMMAND_TOPLEVEL:
prepare_toplevel(state, argc - 1, argv + 1);
break;
case WLRCTL_COMMAND_UNSPEC:
return false;
}
return true;
}
int
main(int argc, char *argv[])
{
struct wlrctl state = {0};
// Usage
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
const char *usage =
"Usage: wlrctl [options] [keyboard|pointer|toplevel] <action>\n"
"\n"
" -h, --help Show a help message and quit\n"
" -v, --version Show a version number and quit\n"
;
// Only allow options up front, so getopt doesn't
// get mad about negative numbers
int cmd_idx = 1;
for ( ; cmd_idx < argc; cmd_idx++ ) {
if (*argv[cmd_idx] != '-') {
break;
}
}
// Option args
int c;
while (true) {
int optind = 0;
c = getopt_long(cmd_idx, argv, "hv", long_options, &optind);
if (c == -1) {
break;
}
switch (c) {
case 'h':
puts(usage);
return EXIT_SUCCESS;
case 'v':
printf("wlrctl v%s\n", WLRCTL_VERSION);
return EXIT_SUCCESS;
default:
puts(usage);
return EXIT_FAILURE;
}
}
if (optind == argc) {
puts(usage);
return EXIT_FAILURE;
}
// Positional args
if (!prepare_command(&state, argc - optind, argv + optind)) {
fprintf(stderr, "Unknown command: '%s'\n", argv[optind]);
puts(usage);
return EXIT_FAILURE;
}
// Bind Globals
state.running = true;
state.display = wl_display_connect(NULL);
assert(state.display);
state.registry = wl_display_get_registry(state.display);
wl_registry_add_listener(state.registry, &wl_registry_listener, &state);
wl_display_roundtrip(state.display);
switch (state.cmd_type) {
case WLRCTL_COMMAND_KEYBOARD:
if (!state.vkbd_mgr) {
die("Virtual Keyboard interface not found!\n");
}
run_keyboard(&state);
break;
case WLRCTL_COMMAND_POINTER:
if (!state.vp_mgr) {
die("Virtual Pointer interface not found!\n");
}
run_pointer(&state);
break;
case WLRCTL_COMMAND_TOPLEVEL:
if (!state.ftl_mgr) {
die("Foreign Toplevel Management interface not found!\n");
}
run_toplevel(&state);
break;
case WLRCTL_COMMAND_UNSPEC:
// unreachable
assert(false);
}
while (state.running) {
if (wl_display_dispatch(state.display) < 0) {
break;
};
}
return state.failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
0707010000000E000081A4000003E800000064000000015F2BC0A700000656000000000000000000000000000000000000002600000000wlrctl-1596702887.6cfacab/meson.buildproject(
'wlrctl',
'c',
version: '0.2.1',
license: 'MIT',
default_options: [
'c_std=c11',
'warning_level=2',
'werror=true',
],
)
cc = meson.get_compiler('c')
datadir = get_option('datadir')
prefix = get_option('prefix')
add_project_arguments('-Wno-unused-parameter', language: 'c')
add_project_arguments('-Wno-missing-braces', language: 'c')
version = '"@0@"'.format(meson.project_version())
add_project_arguments('-DWLRCTL_VERSION=@0@'.format(version), language: 'c')
xkbcommon = dependency('xkbcommon')
wayland_client = dependency('wayland-client')
subdir('protocol')
src_files = [
'main.c',
'ascii_raw_keymap.c',
'keyboard.c',
'pointer.c',
'toplevel.c',
'util.c',
]
includes = include_directories('include')
executable(
'wlrctl',
files(src_files),
dependencies: [
client_protos,
wayland_client,
xkbcommon,
],
include_directories: [includes],
install: true
)
scdoc = dependency('scdoc', native: true, required: get_option('man-pages'))
if scdoc.found()
scdoc_cmd = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
sh = find_program('sh', native: true)
mandir = get_option('mandir')
output = 'wlrctl.1'
custom_target(
output,
input: 'wlrctl.1.scd',
output: output,
command: [sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc_cmd.path(), output)],
install: true,
install_dir: '@0@/man1'.format(mandir)
)
endif
if get_option('zsh-completions')
zsh_completions = files('completions/zsh/_wlrctl')
zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions')
install_data(zsh_completions, install_dir: zsh_install_dir)
endif
# vim: set ts=4 sw=4:
0707010000000F000081A4000003E800000064000000015F2BC0A7000000C3000000000000000000000000000000000000002C00000000wlrctl-1596702887.6cfacab/meson_options.txtoption('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.')
option('man-pages', type: 'feature', value: 'auto', description: 'Install the manual page')
07070100000010000081A4000003E800000064000000015F2BC0A700001409000000000000000000000000000000000000002400000000wlrctl-1596702887.6cfacab/pointer.c#include <assert.h>
#include <linux/input-event-codes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client.h>
#include <wayland-util.h>
#include "common.h"
#include "pointer.h"
#include "util.h"
#include "wlr-virtual-pointer-unstable-v1-client-protocol.h"
static enum pointer_action
parse_action(const char *action)
{
static const struct token actions[] = {
{"click", POINTER_ACTION_CLICK },
{"motion", POINTER_ACTION_MOTION},
{"move", POINTER_ACTION_MOTION},
{"scroll", POINTER_ACTION_SCROLL},
{NULL, POINTER_ACTION_UNSPEC}
};
return matchtok(actions, action);
}
static uint32_t
parse_button(const char *button)
{
static const struct token buttons[] = {
{"left", BTN_LEFT },
{"right", BTN_RIGHT },
{"middle", BTN_MIDDLE },
{"extra", BTN_EXTRA },
{"side", BTN_SIDE },
{"forward", BTN_FORWARD},
{"back", BTN_BACK },
{NULL, 0}
};
return matchtok(buttons, button);
}
static void
parse_fixed(const char *d, wl_fixed_t *fixed)
{
char *end;
int val = strtod(d, &end);
if (end == d || *end){
die("Bad value: '%s'\n", d);
} else {
*fixed = wl_fixed_from_double(val);
}
}
void
prepare_pointer(struct wlrctl *state, int argc, char *argv[])
{
struct wlrctl_pointer_command *cmd = calloc(1, sizeof (struct wlrctl_pointer_command));
assert(cmd);
const char *action = argv[0];
cmd->action = parse_action(action);
switch (cmd->action) {
case POINTER_ACTION_CLICK:
if (argc < 2) {
cmd->button = BTN_LEFT;
} else {
const char *button = argv[1];
cmd->button = parse_button(button);
if (!cmd->button) {
die("Unknown button: '%s'\n", button);
}
}
break;
case POINTER_ACTION_MOTION:
switch (argc) {
case 1:
break;
case 2:
parse_fixed(argv[1], &cmd->dx);
break;
case 3:
parse_fixed(argv[1], &cmd->dx);
parse_fixed(argv[2], &cmd->dy);
break;
default:
die("Extra argument: '%s'\n", argv[3]);
}
break;
case POINTER_ACTION_SCROLL:
switch (argc) {
case 1:
break;
case 2:
parse_fixed(argv[1], &cmd->dy);
break;
case 3:
parse_fixed(argv[1], &cmd->dy);
parse_fixed(argv[2], &cmd->dx);
break;
default:
die("Extra argument: '%s'\n", argv[3]);
}
break;
case POINTER_ACTION_UNSPEC:
die("Unknown pointer action: '%s'\n", action);
}
state->cmd = cmd;
cmd->state = state;
}
static void
complete_pointer(void *data, struct wl_callback *callback, uint32_t serial)
{
struct wlrctl *state = data;
wl_callback_destroy(callback);
state->running = false;
destroy_pointer(state);
}
static struct wl_callback_listener completed_listener = {
.done = complete_pointer
};
static void
pointer_press(struct zwlr_virtual_pointer_v1 *vptr, uint32_t button)
{
zwlr_virtual_pointer_v1_button(vptr, timestamp(), button, WL_POINTER_BUTTON_STATE_PRESSED);
zwlr_virtual_pointer_v1_frame(vptr);
}
static void
pointer_release(struct zwlr_virtual_pointer_v1 *vptr, uint32_t button)
{
zwlr_virtual_pointer_v1_button(vptr, timestamp(), button, WL_POINTER_BUTTON_STATE_RELEASED);
zwlr_virtual_pointer_v1_frame(vptr);
}
static void
pointer_move(struct zwlr_virtual_pointer_v1 *vptr, wl_fixed_t dx, wl_fixed_t dy)
{
if (!dx && !dy) {
return;
} else {
zwlr_virtual_pointer_v1_motion(vptr, timestamp(), dx, dy);
zwlr_virtual_pointer_v1_frame(vptr);
}
}
static void
pointer_scroll(struct zwlr_virtual_pointer_v1 *vptr, wl_fixed_t dy, wl_fixed_t dx)
{
if (!dx && !dy) {
return;
}
if (dx) {
zwlr_virtual_pointer_v1_axis_source(vptr, WL_POINTER_AXIS_SOURCE_FINGER);
zwlr_virtual_pointer_v1_axis(vptr, timestamp(), WL_POINTER_AXIS_HORIZONTAL_SCROLL, dx);
}
if (dy) {
zwlr_virtual_pointer_v1_axis_source(vptr, WL_POINTER_AXIS_SOURCE_FINGER);
zwlr_virtual_pointer_v1_axis(vptr, timestamp(), WL_POINTER_AXIS_VERTICAL_SCROLL, dy);
}
zwlr_virtual_pointer_v1_frame(vptr);
if (dx) {
zwlr_virtual_pointer_v1_axis_source(vptr, WL_POINTER_AXIS_SOURCE_FINGER);
zwlr_virtual_pointer_v1_axis_stop(vptr, timestamp(), WL_POINTER_AXIS_HORIZONTAL_SCROLL);
}
if (dy) {
zwlr_virtual_pointer_v1_axis_source(vptr, WL_POINTER_AXIS_SOURCE_FINGER);
zwlr_virtual_pointer_v1_axis_stop(vptr, timestamp(), WL_POINTER_AXIS_VERTICAL_SCROLL);
}
zwlr_virtual_pointer_v1_frame(vptr);
}
void
run_pointer(struct wlrctl *state)
{
struct wlrctl_pointer_command *cmd = state->cmd;
cmd->device =
zwlr_virtual_pointer_manager_v1_create_virtual_pointer(
state->vp_mgr, state->seat
);
switch (cmd->action) {
case POINTER_ACTION_CLICK:
pointer_press(cmd->device, cmd->button);
pointer_release(cmd->device, cmd->button);
break;
case POINTER_ACTION_MOTION:
pointer_move(cmd->device, cmd->dx, cmd->dy);
break;
case POINTER_ACTION_SCROLL:
pointer_scroll(cmd->device, cmd->dy, cmd->dx);
break;
case POINTER_ACTION_UNSPEC:
// Unreachable
assert(false);
}
struct wl_callback *callback = wl_display_sync(state->display);
wl_callback_add_listener(callback, &completed_listener, state);
}
void
destroy_pointer(struct wlrctl *state)
{
struct wlrctl_pointer_command *cmd = state->cmd;
zwlr_virtual_pointer_v1_destroy(cmd->device);
free(cmd);
}
07070100000011000041ED000003E800000064000000025F2BC0A700000000000000000000000000000000000000000000002300000000wlrctl-1596702887.6cfacab/protocol07070100000012000081A4000003E800000064000000015F2BC0A700000403000000000000000000000000000000000000002F00000000wlrctl-1596702887.6cfacab/protocol/meson.build# wl_protocol_dir = wayland_protos.get_variable(pkgconfig: 'pkgdatadir')
wayland_scanner = find_program('wayland-scanner')
wayland_scanner_code = generator(
wayland_scanner,
output: '@BASENAME@-protocol.c',
arguments: ['private-code', '@INPUT@', '@OUTPUT@'],
)
wayland_scanner_client = generator(
wayland_scanner,
output: '@BASENAME@-client-protocol.h',
arguments: ['client-header', '@INPUT@', '@OUTPUT@'],
)
protocols = [
'virtual-keyboard-unstable-v1.xml',
'wlr-virtual-pointer-unstable-v1.xml',
'wlr-foreign-toplevel-management-unstable-v1.xml',
]
client_protos_src = []
client_protos_headers = []
foreach xml : protocols
client_protos_src += wayland_scanner_code.process(xml)
client_protos_headers += wayland_scanner_client.process(xml)
endforeach
lib_client_protos = static_library(
'client_protos',
client_protos_src + client_protos_headers,
dependencies: [wayland_client]
)
client_protos = declare_dependency(
link_with: lib_client_protos,
sources: client_protos_headers,
)
# vim: set ts=4 sw=4:
07070100000013000081A4000003E800000064000000015F2BC0A700001316000000000000000000000000000000000000004400000000wlrctl-1596702887.6cfacab/protocol/virtual-keyboard-unstable-v1.xml<?xml version="1.0" encoding="UTF-8"?>
<protocol name="virtual_keyboard_unstable_v1">
<copyright>
Copyright © 2008-2011 Kristian Høgsberg
Copyright © 2010-2013 Intel Corporation
Copyright © 2012-2013 Collabora, Ltd.
Copyright © 2018 Purism SPC
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="zwp_virtual_keyboard_v1" version="1">
<description summary="virtual keyboard">
The virtual keyboard provides an application with requests which emulate
the behaviour of a physical keyboard.
This interface can be used by clients on its own to provide raw input
events, or it can accompany the input method protocol.
</description>
<request name="keymap">
<description summary="keyboard mapping">
Provide a file descriptor to the compositor which can be
memory-mapped to provide a keyboard mapping description.
Format carries a value from the keymap_format enumeration.
</description>
<arg name="format" type="uint" summary="keymap format"/>
<arg name="fd" type="fd" summary="keymap file descriptor"/>
<arg name="size" type="uint" summary="keymap size, in bytes"/>
</request>
<enum name="error">
<entry name="no_keymap" value="0" summary="No keymap was set"/>
</enum>
<request name="key">
<description summary="key event">
A key was pressed or released.
The time argument is a timestamp with millisecond granularity, with an
undefined base. All requests regarding a single object must share the
same clock.
Keymap must be set before issuing this request.
State carries a value from the key_state enumeration.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="key" type="uint" summary="key that produced the event"/>
<arg name="state" type="uint" summary="physical state of the key"/>
</request>
<request name="modifiers">
<description summary="modifier and group state">
Notifies the compositor that the modifier and/or group state has
changed, and it should update state.
The client should use wl_keyboard.modifiers event to synchronize its
internal state with seat state.
Keymap must be set before issuing this request.
</description>
<arg name="mods_depressed" type="uint" summary="depressed modifiers"/>
<arg name="mods_latched" type="uint" summary="latched modifiers"/>
<arg name="mods_locked" type="uint" summary="locked modifiers"/>
<arg name="group" type="uint" summary="keyboard layout"/>
</request>
<request name="destroy" type="destructor" since="1">
<description summary="destroy the virtual keyboard keyboard object"/>
</request>
</interface>
<interface name="zwp_virtual_keyboard_manager_v1" version="1">
<description summary="virtual keyboard manager">
A virtual keyboard manager allows an application to provide keyboard
input events as if they came from a physical keyboard.
</description>
<enum name="error">
<entry name="unauthorized" value="0" summary="client not authorized to use the interface"/>
</enum>
<request name="create_virtual_keyboard">
<description summary="Create a new virtual keyboard">
Creates a new virtual keyboard associated to a seat.
If the compositor enables a keyboard to perform arbitrary actions, it
should present an error when an untrusted client requests a new
keyboard.
</description>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="id" type="new_id" interface="zwp_virtual_keyboard_v1"/>
</request>
</interface>
</protocol>
07070100000014000081A4000003E800000064000000015F2BC0A700002B7B000000000000000000000000000000000000005300000000wlrctl-1596702887.6cfacab/protocol/wlr-foreign-toplevel-management-unstable-v1.xml<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_foreign_toplevel_management_unstable_v1">
<copyright>
Copyright © 2018 Ilia Bozhinov
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of
the copyright holders not be used in advertising or publicity
pertaining to distribution of the software without specific,
written prior permission. The copyright holders make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
</copyright>
<interface name="zwlr_foreign_toplevel_manager_v1" version="2">
<description summary="list and control opened apps">
The purpose of this protocol is to enable the creation of taskbars
and docks by providing them with a list of opened applications and
letting them request certain actions on them, like maximizing, etc.
After a client binds the zwlr_foreign_toplevel_manager_v1, each opened
toplevel window will be sent via the toplevel event
</description>
<event name="toplevel">
<description summary="a toplevel has been created">
This event is emitted whenever a new toplevel window is created. It
is emitted for all toplevels, regardless of the app that has created
them.
All initial details of the toplevel(title, app_id, states, etc.) will
be sent immediately after this event via the corresponding events in
zwlr_foreign_toplevel_handle_v1.
</description>
<arg name="toplevel" type="new_id" interface="zwlr_foreign_toplevel_handle_v1"/>
</event>
<request name="stop">
<description summary="stop sending events">
Indicates the client no longer wishes to receive events for new toplevels.
However the compositor may emit further toplevel_created events, until
the finished event is emitted.
The client must not send any more requests after this one.
</description>
</request>
<event name="finished">
<description summary="the compositor has finished with the toplevel manager">
This event indicates that the compositor is done sending events to the
zwlr_foreign_toplevel_manager_v1. The server will destroy the object
immediately after sending this request, so it will become invalid and
the client should free any resources associated with it.
</description>
</event>
</interface>
<interface name="zwlr_foreign_toplevel_handle_v1" version="2">
<description summary="an opened toplevel">
A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel
window. Each app may have multiple opened toplevels.
Each toplevel has a list of outputs it is visible on, conveyed to the
client with the output_enter and output_leave events.
</description>
<event name="title">
<description summary="title change">
This event is emitted whenever the title of the toplevel changes.
</description>
<arg name="title" type="string"/>
</event>
<event name="app_id">
<description summary="app-id change">
This event is emitted whenever the app-id of the toplevel changes.
</description>
<arg name="app_id" type="string"/>
</event>
<event name="output_enter">
<description summary="toplevel entered an output">
This event is emitted whenever the toplevel becomes visible on
the given output. A toplevel may be visible on multiple outputs.
</description>
<arg name="output" type="object" interface="wl_output"/>
</event>
<event name="output_leave">
<description summary="toplevel left an output">
This event is emitted whenever the toplevel stops being visible on
the given output. It is guaranteed that an entered-output event
with the same output has been emitted before this event.
</description>
<arg name="output" type="object" interface="wl_output"/>
</event>
<request name="set_maximized">
<description summary="requests that the toplevel be maximized">
Requests that the toplevel be maximized. If the maximized state actually
changes, this will be indicated by the state event.
</description>
</request>
<request name="unset_maximized">
<description summary="requests that the toplevel be unmaximized">
Requests that the toplevel be unmaximized. If the maximized state actually
changes, this will be indicated by the state event.
</description>
</request>
<request name="set_minimized">
<description summary="requests that the toplevel be minimized">
Requests that the toplevel be minimized. If the minimized state actually
changes, this will be indicated by the state event.
</description>
</request>
<request name="unset_minimized">
<description summary="requests that the toplevel be unminimized">
Requests that the toplevel be unminimized. If the minimized state actually
changes, this will be indicated by the state event.
</description>
</request>
<request name="activate">
<description summary="activate the toplevel">
Request that this toplevel be activated on the given seat.
There is no guarantee the toplevel will be actually activated.
</description>
<arg name="seat" type="object" interface="wl_seat"/>
</request>
<enum name="state">
<description summary="types of states on the toplevel">
The different states that a toplevel can have. These have the same meaning
as the states with the same names defined in xdg-toplevel
</description>
<entry name="maximized" value="0" summary="the toplevel is maximized"/>
<entry name="minimized" value="1" summary="the toplevel is minimized"/>
<entry name="activated" value="2" summary="the toplevel is active"/>
<entry name="fullscreen" value="3" summary="the toplevel is fullscreen" since="2"/>
</enum>
<event name="state">
<description summary="the toplevel state changed">
This event is emitted immediately after the zlw_foreign_toplevel_handle_v1
is created and each time the toplevel state changes, either because of a
compositor action or because of a request in this protocol.
</description>
<arg name="state" type="array"/>
</event>
<event name="done">
<description summary="all information about the toplevel has been sent">
This event is sent after all changes in the toplevel state have been
sent.
This allows changes to the zwlr_foreign_toplevel_handle_v1 properties
to be seen as atomic, even if they happen via multiple events.
</description>
</event>
<request name="close">
<description summary="request that the toplevel be closed">
Send a request to the toplevel to close itself. The compositor would
typically use a shell-specific method to carry out this request, for
example by sending the xdg_toplevel.close event. However, this gives
no guarantees the toplevel will actually be destroyed. If and when
this happens, the zwlr_foreign_toplevel_handle_v1.closed event will
be emitted.
</description>
</request>
<request name="set_rectangle">
<description summary="the rectangle which represents the toplevel">
The rectangle of the surface specified in this request corresponds to
the place where the app using this protocol represents the given toplevel.
It can be used by the compositor as a hint for some operations, e.g
minimizing. The client is however not required to set this, in which
case the compositor is free to decide some default value.
If the client specifies more than one rectangle, only the last one is
considered.
The dimensions are given in surface-local coordinates.
Setting width=height=0 removes the already-set rectangle.
</description>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="x" type="int"/>
<arg name="y" type="int"/>
<arg name="width" type="int"/>
<arg name="height" type="int"/>
</request>
<enum name="error">
<entry name="invalid_rectangle" value="0"
summary="the provided rectangle is invalid"/>
</enum>
<event name="closed">
<description summary="this toplevel has been destroyed">
This event means the toplevel has been destroyed. It is guaranteed there
won't be any more events for this zwlr_foreign_toplevel_handle_v1. The
toplevel itself becomes inert so any requests will be ignored except the
destroy request.
</description>
</event>
<request name="destroy" type="destructor">
<description summary="destroy the zwlr_foreign_toplevel_handle_v1 object">
Destroys the zwlr_foreign_toplevel_handle_v1 object.
This request should be called either when the client does not want to
use the toplevel anymore or after the closed event to finalize the
destruction of the object.
</description>
</request>
<!-- Version 2 additions -->
<request name="set_fullscreen" since="2">
<description summary="request that the toplevel be fullscreened">
Requests that the toplevel be fullscreened on the given output. If the
fullscreen state and/or the outputs the toplevel is visible on actually
change, this will be indicated by the state and output_enter/leave
events.
The output parameter is only a hint to the compositor. Also, if output
is NULL, the compositor should decide which output the toplevel will be
fullscreened on, if at all.
</description>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
</request>
<request name="unset_fullscreen" since="2">
<description summary="request that the toplevel be unfullscreened">
Requests that the toplevel be unfullscreened. If the fullscreen state
actually changes, this will be indicated by the state event.
</description>
</request>
</interface>
</protocol>
07070100000015000081A4000003E800000064000000015F2BC0A700001AEF000000000000000000000000000000000000004700000000wlrctl-1596702887.6cfacab/protocol/wlr-virtual-pointer-unstable-v1.xml<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_virtual_pointer_unstable_v1">
<copyright>
Copyright © 2019 Josef Gajdusek
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="zwlr_virtual_pointer_v1" version="2">
<description summary="virtual pointer">
This protocol allows clients to emulate a physical pointer device. The
requests are mostly mirror opposites of those specified in wl_pointer.
</description>
<enum name="error">
<entry name="invalid_axis" value="0"
summary="client sent invalid axis enumeration value" />
<entry name="invalid_axis_source" value="1"
summary="client sent invalid axis source enumeration value" />
</enum>
<request name="motion">
<description summary="pointer relative motion event">
The pointer has moved by a relative amount to the previous request.
Values are in the global compositor space.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="dx" type="fixed" summary="displacement on the x-axis"/>
<arg name="dy" type="fixed" summary="displacement on the y-axis"/>
</request>
<request name="motion_absolute">
<description summary="pointer absolute motion event">
The pointer has moved in an absolute coordinate frame.
Value of x can range from 0 to x_extent, value of y can range from 0
to y_extent.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="x" type="uint" summary="position on the x-axis"/>
<arg name="y" type="uint" summary="position on the y-axis"/>
<arg name="x_extent" type="uint" summary="extent of the x-axis"/>
<arg name="y_extent" type="uint" summary="extent of the y-axis"/>
</request>
<request name="button">
<description summary="button event">
A button was pressed or released.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="button" type="uint" summary="button that produced the event"/>
<arg name="state" type="uint" enum="wl_pointer.button_state" summary="physical state of the button"/>
</request>
<request name="axis">
<description summary="axis event">
Scroll and other axis requests.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>
<arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>
</request>
<request name="frame">
<description summary="end of a pointer event sequence">
Indicates the set of events that logically belong together.
</description>
</request>
<request name="axis_source">
<description summary="axis source event">
Source information for scroll and other axis.
</description>
<arg name="axis_source" type="uint" enum="wl_pointer.axis_source" summary="source of the axis event"/>
</request>
<request name="axis_stop">
<description summary="axis stop event">
Stop notification for scroll and other axes.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="axis" type="uint" enum="wl_pointer.axis" summary="the axis stopped with this event"/>
</request>
<request name="axis_discrete">
<description summary="axis click event">
Discrete step information for scroll and other axes.
This event allows the client to extend data normally sent using the axis
event with discrete value.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="axis" type="uint" enum="wl_pointer.axis" summary="axis type"/>
<arg name="value" type="fixed" summary="length of vector in touchpad coordinates"/>
<arg name="discrete" type="int" summary="number of steps"/>
</request>
<request name="destroy" type="destructor" since="1">
<description summary="destroy the virtual pointer object"/>
</request>
</interface>
<interface name="zwlr_virtual_pointer_manager_v1" version="2">
<description summary="virtual pointer manager">
This object allows clients to create individual virtual pointer objects.
</description>
<request name="create_virtual_pointer">
<description summary="Create a new virtual pointer">
Creates a new virtual pointer. The optional seat is a suggestion to the
compositor.
</description>
<arg name="seat" type="object" interface="wl_seat" allow-null="true"/>
<arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>
</request>
<request name="destroy" type="destructor" since="1">
<description summary="destroy the virtual pointer manager"/>
</request>
<!-- Version 2 additions -->
<request name="create_virtual_pointer_with_output" since="2">
<description summary="Create a new virtual pointer">
Creates a new virtual pointer. The seat and the output arguments are
optional. If the seat argument is set, the compositor should assign the
input device to the requested seat. If the output argument is set, the
compositor should map the input device to the requested output.
</description>
<arg name="seat" type="object" interface="wl_seat" allow-null="true"/>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
<arg name="id" type="new_id" interface="zwlr_virtual_pointer_v1"/>
</request>
</interface>
</protocol>
07070100000016000081A4000003E800000064000000015F2BC0A700002C52000000000000000000000000000000000000002500000000wlrctl-1596702887.6cfacab/toplevel.c#define _DEFAULT_SOURCE
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wayland-client.h>
#include "common.h"
#include "toplevel.h"
#include "util.h"
#include "wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"
static void noop() {}
static enum toplevel_action
parse_action(const char *action)
{
static const struct token actions[] = {
{"activate", TOPLEVEL_ACTION_ACTIVATE },
{"close", TOPLEVEL_ACTION_CLOSE },
{"find", TOPLEVEL_ACTION_FIND },
{"focus", TOPLEVEL_ACTION_ACTIVATE },
{"fullscreen", TOPLEVEL_ACTION_FULLSCREEN},
{"list", TOPLEVEL_ACTION_LIST },
{"maximize", TOPLEVEL_ACTION_MAXIMIZE },
{"minimize", TOPLEVEL_ACTION_MINIMIZE },
{"wait", TOPLEVEL_ACTION_WAIT },
{"waitfor", TOPLEVEL_ACTION_WAITFOR },
{NULL, TOPLEVEL_ACTION_UNSPEC}
};
return matchtok(actions, action);
}
static enum toplevel_attr
parse_state(const char *state, bool *enabled){
static const struct token states[] = {
{"maximized", TOPLEVEL_ATTR_MAXIMIZED },
{"minimized", TOPLEVEL_ATTR_MINIMIZED },
{"activated", TOPLEVEL_ATTR_ACTIVATED },
{"active", TOPLEVEL_ATTR_ACTIVATED },
{"focused", TOPLEVEL_ATTR_ACTIVATED },
{"fullscreen", TOPLEVEL_ATTR_FULLSCREEN},
{NULL, TOPLEVEL_ATTR_UNSPEC}
};
if (strncmp(state, "-", 1) == 0) {
*enabled = false;
state += 1;
} else if (
strncmp(state, "in", 2) == 0 ||
strncmp(state, "un", 2) == 0 ) {
*enabled = false;
state += 2;
} else {
*enabled = true;
}
return matchtok(states, state);
}
static void
append(struct wl_array *arr, char *str)
{
char **p = wl_array_add(arr, sizeof (char *));
if (!p) {
die("Could not allocate pointer for matchspec\n");
} else {
*p = str;
}
}
static bool
contains_value(struct wl_array *arr, int value) {
if (!value) {
return false;
}
int *cursor;
wl_array_for_each(cursor, arr) {
if (*cursor == value) {
return true;
}
}
return false;
}
static bool
contains_str(struct wl_array *arr, char *str)
{
if (!str) {
return false;
}
char **cursor;
wl_array_for_each(cursor, arr) {
if (strcmp(str, *cursor) == 0) {
return true;
}
}
return false;
}
static void
matchspec_init(struct toplevel_matchspec *matchspec)
{
wl_array_init(&matchspec->app_ids);
wl_array_init(&matchspec->titles);
}
static void
matchspec_release(struct toplevel_matchspec *matchspec)
{
wl_array_release(&matchspec->app_ids);
wl_array_release(&matchspec->titles);
}
static void
matchspec_add_match(struct toplevel_matchspec *matchspec, char *match)
{
char *value = match;
char *attr = strsep(&value, ":");
if (!value) {
matchspec->attrs |= TOPLEVEL_ATTR_APPID;
append(&matchspec->app_ids, attr);
return;
}
bool enabled = true;
struct token attrs[] = {
{"app-id", TOPLEVEL_ATTR_APPID },
{"app_id", TOPLEVEL_ATTR_APPID },
{"title", TOPLEVEL_ATTR_TITLE },
{"state", parse_state(value, &enabled)},
{NULL, TOPLEVEL_ATTR_UNSPEC}
};
enum toplevel_attr pattr = matchtok(attrs, attr);
switch (pattr) {
case TOPLEVEL_ATTR_APPID:
matchspec->attrs |= pattr;
append(&matchspec->app_ids, value);
return;
case TOPLEVEL_ATTR_TITLE:
matchspec->attrs |= pattr;
append(&matchspec->titles, value);
return;
case TOPLEVEL_ATTR_MAXIMIZED:
matchspec->attrs |= pattr;
matchspec->maximized = enabled;
break;
case TOPLEVEL_ATTR_MINIMIZED:
matchspec->attrs |= pattr;
matchspec->minimized = enabled;
break;
case TOPLEVEL_ATTR_ACTIVATED:
matchspec->attrs |= pattr;
matchspec->activated = enabled;
break;
case TOPLEVEL_ATTR_FULLSCREEN:
matchspec->attrs |= pattr;
matchspec->fullscreen = enabled;
break;
case TOPLEVEL_ATTR_UNSPEC:
default:
die("Unknown attribute: '%s:%s'\n", attr, value);
}
return;
}
static bool
is_matched(struct toplevel_data *data)
{
struct toplevel_matchspec *matchspec = &data->cmd->matchspec;
if (matchspec->attrs & TOPLEVEL_ATTR_APPID) {
if (!contains_str(&matchspec->app_ids, data->app_id)) {
return false;
}
}
if (matchspec->attrs & TOPLEVEL_ATTR_TITLE) {
if (!contains_str(&matchspec->titles, data->title)) {
return false;
}
}
if (matchspec->attrs & TOPLEVEL_ATTR_MAXIMIZED) {
if (contains_value(&data->state,
ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED) ^
matchspec->maximized) {
return false;
}
}
if (matchspec->attrs & TOPLEVEL_ATTR_MINIMIZED) {
if (contains_value(&data->state,
ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED) ^
matchspec->minimized) {
return false;
}
}
if (matchspec->attrs & TOPLEVEL_ATTR_ACTIVATED) {
if (contains_value(&data->state,
ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED) ^
matchspec->activated) {
return false;
}
}
if (matchspec->attrs & TOPLEVEL_ATTR_FULLSCREEN) {
if (contains_value(&data->state,
ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN) ^
matchspec->fullscreen) {
return false;
}
}
return true;
}
struct toplevel_data *
toplevel_data_create(struct wlrctl_toplevel_command *cmd)
{
struct toplevel_data *data = calloc(1, sizeof (struct toplevel_data));
if (!data) {
die("Failed to allocate toplevel data\n");
}
wl_array_init(&data->state);
data->cmd = cmd;
wl_list_insert(&cmd->toplevels, &data->link);
return data;
}
void
toplevel_data_destroy(struct toplevel_data *data)
{
free(data->app_id);
free(data->title);
wl_array_release(&data->state);
free(data);
}
static void
zwlr_foreign_toplevel_handle_v1_handle_title(void *user_data,
struct zwlr_foreign_toplevel_handle_v1 *toplevel,
const char *title
)
{
struct toplevel_data *data = user_data;
data->title = strdup(title);
}
static void
zwlr_foreign_toplevel_handle_v1_handle_app_id(void *user_data,
struct zwlr_foreign_toplevel_handle_v1 *toplevel,
const char *app_id
)
{
struct toplevel_data *data = user_data;
data->app_id = strdup(app_id);
}
static void
zwlr_foreign_toplevel_handle_v1_handle_state(void *user_data,
struct zwlr_foreign_toplevel_handle_v1 *toplevel,
struct wl_array *state
)
{
struct toplevel_data *data = user_data;
wl_array_copy(&data->state, state);
}
static void
zwlr_foreign_toplevel_handle_v1_handle_done(void *user_data,
struct zwlr_foreign_toplevel_handle_v1 *toplevel
)
{
struct toplevel_data *data = user_data;
if (data->cmd->action != TOPLEVEL_ACTION_WAITFOR && data->done) {
return;
} else {
data->done = true;
}
if (data->cmd->complete || !is_matched(data)) {
return;
} else {
data->cmd->any = true;
data->matched = true;
}
switch (data->cmd->action) {
case TOPLEVEL_ACTION_MINIMIZE:
zwlr_foreign_toplevel_handle_v1_set_minimized(toplevel);
break;
case TOPLEVEL_ACTION_MAXIMIZE:
zwlr_foreign_toplevel_handle_v1_set_maximized(toplevel);
break;
case TOPLEVEL_ACTION_ACTIVATE:
zwlr_foreign_toplevel_handle_v1_activate(toplevel, data->cmd->state->seat);
data->cmd->complete = true;
stop_toplevel(data->cmd->state);
break;
case TOPLEVEL_ACTION_FULLSCREEN:
zwlr_foreign_toplevel_handle_v1_set_fullscreen(toplevel, NULL);
break;
case TOPLEVEL_ACTION_CLOSE:
zwlr_foreign_toplevel_handle_v1_close(toplevel);
break;
case TOPLEVEL_ACTION_LIST:
if (data->app_id) {
printf("%s: %s\n", data->app_id, data->title ? data->title : "");
}
break;
case TOPLEVEL_ACTION_FIND:
case TOPLEVEL_ACTION_WAITFOR:
data->cmd->complete = true;
stop_toplevel(data->cmd->state);
break;
case TOPLEVEL_ACTION_WAIT:
data->cmd->waiting++;
break;
case TOPLEVEL_ACTION_UNSPEC:
// unreachable
assert(false);
}
}
static void
zwlr_foreign_toplevel_handle_v1_handle_closed(
void *user_data, struct zwlr_foreign_toplevel_handle_v1 *toplevel)
{
struct toplevel_data *data = user_data;
zwlr_foreign_toplevel_handle_v1_destroy(toplevel);
if (data->cmd->complete || !data->matched) {
return;
}
if (data->cmd->action == TOPLEVEL_ACTION_WAIT) {
data->cmd->waiting--;
if (data->cmd->waiting <= 0) {
data->cmd->complete = true;
stop_toplevel(data->cmd->state);
}
}
}
static struct zwlr_foreign_toplevel_handle_v1_listener
zwlr_foreign_toplevel_handle_v1_listener = {
.title = zwlr_foreign_toplevel_handle_v1_handle_title,
.app_id = zwlr_foreign_toplevel_handle_v1_handle_app_id,
.output_enter = noop,
.output_leave = noop,
.state = zwlr_foreign_toplevel_handle_v1_handle_state,
.done = zwlr_foreign_toplevel_handle_v1_handle_done,
.closed = zwlr_foreign_toplevel_handle_v1_handle_closed,
};
static void
zwlr_foreign_toplevel_manager_v1_handle_toplevel(
void *data,
struct zwlr_foreign_toplevel_manager_v1 *manager,
struct zwlr_foreign_toplevel_handle_v1 *toplevel
)
{
struct wlrctl *state = data;
struct wlrctl_toplevel_command *cmd = state->cmd;
struct toplevel_data *toplevel_data = toplevel_data_create(cmd);
zwlr_foreign_toplevel_handle_v1_add_listener(
toplevel,
&zwlr_foreign_toplevel_handle_v1_listener,
toplevel_data
);
}
static void
zwlr_foreign_toplevel_manager_v1_handle_finished(
void *data,
struct zwlr_foreign_toplevel_manager_v1 *manager
)
{
struct wlrctl *state = data;
state->running = false;
destroy_toplevel(state);
}
static struct zwlr_foreign_toplevel_manager_v1_listener
zwlr_foreign_toplevel_manager_v1_listener = {
.toplevel = zwlr_foreign_toplevel_manager_v1_handle_toplevel,
.finished = zwlr_foreign_toplevel_manager_v1_handle_finished,
};
void
prepare_toplevel(struct wlrctl *state, int argc, char *argv[])
{
struct wlrctl_toplevel_command *cmd = calloc(1, sizeof (struct wlrctl_toplevel_command));
assert(cmd);
wl_list_init(&cmd->toplevels);
matchspec_init(&cmd->matchspec);
if (argc == 0) {
die("Missing toplevel action\n");
}
char *action = argv[0];
cmd->action = parse_action(action);
if (!cmd->action) {
die("Unknown toplevel action: '%s'\n", action);
}
for (int i = 1; i < argc; i++) {
matchspec_add_match(&cmd->matchspec, argv[i]);
}
state->cmd = cmd;
cmd->state = state;
}
void
stop_toplevel(struct wlrctl *state)
{
zwlr_foreign_toplevel_manager_v1_stop(state->ftl_mgr);
}
void
complete_toplevel(void *data, struct wl_callback *callback, uint32_t serial)
{
struct wlrctl *state = data;
struct wlrctl_toplevel_command *cmd = state->cmd;
wl_callback_destroy(callback);
if (cmd->action == TOPLEVEL_ACTION_WAITFOR ||
(cmd->action == TOPLEVEL_ACTION_WAIT && (cmd->waiting > 0))) {
return;
}
if (!cmd->complete) {
cmd->complete = true;
cmd->state->failed = !cmd->any;
stop_toplevel(state);
}
}
static struct wl_callback_listener complete_listener = {
.done = complete_toplevel
};
void
run_toplevel(struct wlrctl *state)
{
struct wlrctl_toplevel_command *cmd = state->cmd;
zwlr_foreign_toplevel_manager_v1_add_listener(
state->ftl_mgr,
&zwlr_foreign_toplevel_manager_v1_listener,
state
);
if (cmd->action == TOPLEVEL_ACTION_LIST) {
stop_toplevel(state);
} else {
struct wl_callback *complete = wl_display_sync(state->display);
wl_callback_add_listener(complete, &complete_listener, state);
}
}
void
destroy_toplevel(struct wlrctl *state)
{
struct wlrctl_toplevel_command *cmd = state->cmd;
matchspec_release(&cmd->matchspec);
// Release toplevels
struct toplevel_data *data, *tmp;
wl_list_for_each_safe(data, tmp, &cmd->toplevels, link) {
wl_list_remove(&data->link);
toplevel_data_destroy(data);
}
free(cmd);
}
07070100000017000081A4000003E800000064000000015F2BC0A700000283000000000000000000000000000000000000002100000000wlrctl-1596702887.6cfacab/util.c#define _POSIX_C_SOURCE 200112L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "util.h"
int
matchtok(const struct token tokens[], const char *name)
{
const struct token *tok;
for (tok = tokens; tok->name != NULL; tok++) {
if (strcmp(tok->name, name) == 0) {
break;
}
}
return tok->value;
}
int
timestamp()
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
int ms = 1000 * tp.tv_sec + tp.tv_nsec / 1000000;
return ms;
}
void
die(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
exit(EXIT_FAILURE);
}
07070100000018000081A4000003E800000064000000015F2BC0A700000A2B000000000000000000000000000000000000002700000000wlrctl-1596702887.6cfacab/wlrctl.1.scdwlrctl(1)
# NAME
wlrctl - A command line utility for miscellaneous wlroots extensions
# SYNOPSIS
wlrctl [options...] [command]
# OPTIONS
*-h, --help*
Show a help message and quit.
*-v, --version*
Show the wlrctl version and quit.
# COMMANDS
*keyboard* <action>
Use a virtual keyboard.
*pointer* <action>
Use a virtual pointer device.
*window|toplevel* <action>
Use the foreign toplevel interface.
# KEYBOARD ACTIONS
*type* <string>
Send a string to be typed into the focused client
# POINTER ACTIONS
*click* [button]
Click a mouse button. If unspecified, clicks the default (left) button.
*move* <dx> <dy>
Move the cursor. _dx_ is the displacement in positive-right direction,
_dy_ is the displacement in the positive-downward direction. Negative
numbers are allowed. Units are pixels.
*scroll* <dy> <dx>
Scroll the cursor. _dy_ is the amount of vertical scroll, _dx_ is the
amount of horizontal scroll. Negative numbers are allowed.
# TOPLEVEL ACTIONS
*minimize* [matches...]
Instruct the compositor to minimize matching windows.
*maximize* [matches...]
Instruct the compositor to maximize matching windows.
*fullscreen* [matches...]
Instruct the compositor to fullscreen matching windows.
*focus* [matches...]
Instruct the compositor to focus matching windows.
*find* [matches...]
Exit with a successful return code iff there is at least one window
matching the provided criteria.
*wait* [matches...]
Wait to return a successful return code until all the matching windows
have closed. If there are no matches, exit with a failing return code
immediately.
*waitfor* [matches...]
Wait to return a successful return code until there is at least one
window that matches the requested criteria.
# TOPLEVEL MATCHSPEC
A match is a colon separated attribute/value pair. e.g. To match a firefox
window, a suitable match value is _app\_id:firefox_. You may give any number of
match specifiers, and a window must match all of them to be considered. If the
app\_id or title keys are specified more than once, a window may match any of
the given values. Otherwise later key value pairs override previous ones. A
match without a key is assumed to be an app_id, so just _firefox_ works in the
example above.
Currently supported attributes are: _app_id_, _title_, and _state_.
Supported state values are: _maximized_, _minimized_, _active_, and
_fullscreen_, and their negations: _unmaximized_, _unminimized_, _inactive_,
and _unfullscreen_. You can also use a '-' prefix, for example
_state:-fullscreen_.
# AUTHOR
Written by Ronan Pigott <rpigott@berkeley.edu>
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!138 blocks