examples/foreign-toplevel: Add documenation and output selection

This commit is contained in:
fwsmit 2021-01-22 23:35:06 +01:00 committed by Simon Ser
parent 0db191d3bf
commit 1b8330d1f8
1 changed files with 46 additions and 27 deletions

View File

@ -9,26 +9,27 @@
#define WLR_FOREIGN_TOPLEVEL_MANAGEMENT_VERSION 3 #define WLR_FOREIGN_TOPLEVEL_MANAGEMENT_VERSION 3
/**
* Usage: static void print_help(void) {
* 1. foreign-toplevel static const char usage[] =
* Prints a list of opened toplevels "Usage: foreign-toplevel [OPTIONS] ...\n"
* 2. foreign-toplevel -f <id> "Manage and view information about toplevel windows.\n"
* Focus the toplevel with the given id "\n"
* 3. foreign-toplevel -a <id> " -f <id> focus\n"
* Maximize the toplevel with the given id " -s <id> fullscreen\n"
* 4. foreign-toplevel -u <id> " -o <output_id> select output for fullscreen toplevel to appear on. Use this\n"
* Unmaximize the toplevel with the given id " option with -s. View available outputs with wayland-info.\n"
* 5. foreign-toplevel -i <id> " -S <id> unfullscreen\n"
* Minimize the toplevel with the given id " -a <id> maximize\n"
* 6. foreign-toplevel -r <id> " -u <id> unmaximize\n"
* Restore(unminimize) the toplevel with the given id " -i <id> minimize\n"
* 7. foreign-toplevel -c <id> " -r <id> restore(unminimize)\n"
* Close the toplevel with the given id " -c <id> close\n"
* 8. foreign-toplevel -m " -m continuously print changes to the list of opened toplevels\n"
* Continuously print changes to the list of opened toplevels. " Can be used together with some of the previous options.\n"
* Can be used together with some of the previous options. " -h print help message and quit\n";
*/ fprintf(stderr, "%s", usage);
}
enum toplevel_state_field { enum toplevel_state_field {
TOPLEVEL_STATE_MAXIMIZED = (1 << 0), TOPLEVEL_STATE_MAXIMIZED = (1 << 0),
@ -39,6 +40,8 @@ enum toplevel_state_field {
}; };
static const uint32_t no_parent = (uint32_t)-1; static const uint32_t no_parent = (uint32_t)-1;
static struct wl_output *pref_output = NULL;
static uint32_t pref_output_id = UINT32_MAX;
struct toplevel_state { struct toplevel_state {
char *title; char *title;
@ -271,9 +274,11 @@ struct wl_seat *seat = NULL;
static void handle_global(void *data, struct wl_registry *registry, static void handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version) { uint32_t name, const char *interface, uint32_t version) {
if (strcmp(interface, wl_output_interface.name) == 0) { if (strcmp(interface, wl_output_interface.name) == 0) {
struct wl_output *output = wl_registry_bind(registry, name, if (name == pref_output_id) {
&wl_output_interface, version); pref_output = wl_registry_bind(registry, name,
wl_output_set_user_data(output, (void*)(size_t)name); // assign some ID to the output &wl_output_interface, version);
}
} else if (strcmp(interface, } else if (strcmp(interface,
zwlr_foreign_toplevel_manager_v1_interface.name) == 0) { zwlr_foreign_toplevel_manager_v1_interface.name) == 0) {
toplevel_manager = wl_registry_bind(registry, name, toplevel_manager = wl_registry_bind(registry, name,
@ -324,8 +329,7 @@ int main(int argc, char **argv) {
int one_shot = 1; int one_shot = 1;
int c; int c;
// TODO maybe print usage with -h? while ((c = getopt(argc, argv, "f:a:u:i:r:c:s:S:mo:h")) != -1) {
while ((c = getopt(argc, argv, "f:a:u:i:r:c:s:S:m")) != -1) {
switch (c) { switch (c) {
case 'f': case 'f':
focus_id = atoi(optarg); focus_id = atoi(optarg);
@ -354,6 +358,17 @@ int main(int argc, char **argv) {
case 'm': case 'm':
one_shot = 0; one_shot = 0;
break; break;
case 'o':
pref_output_id = atoi(optarg);
break;
case '?':
print_help();
return EXIT_FAILURE;
break;
case 'h':
print_help();
return EXIT_SUCCESS;
break;
} }
} }
@ -391,7 +406,11 @@ int main(int argc, char **argv) {
zwlr_foreign_toplevel_handle_v1_unset_minimized(toplevel->zwlr_toplevel); zwlr_foreign_toplevel_handle_v1_unset_minimized(toplevel->zwlr_toplevel);
} }
if ((toplevel = toplevel_by_id_or_bail(fullscreen_id))) { if ((toplevel = toplevel_by_id_or_bail(fullscreen_id))) {
zwlr_foreign_toplevel_handle_v1_set_fullscreen(toplevel->zwlr_toplevel, NULL); if (pref_output_id != UINT32_MAX && pref_output == NULL) {
fprintf(stderr, "Could not find output %i\n", pref_output_id);
}
zwlr_foreign_toplevel_handle_v1_set_fullscreen(toplevel->zwlr_toplevel, pref_output);
} }
if ((toplevel = toplevel_by_id_or_bail(unfullscreen_id))) { if ((toplevel = toplevel_by_id_or_bail(unfullscreen_id))) {
zwlr_foreign_toplevel_handle_v1_unset_fullscreen(toplevel->zwlr_toplevel); zwlr_foreign_toplevel_handle_v1_unset_fullscreen(toplevel->zwlr_toplevel);