From 1b8330d1f8b881a4ed49c3c2fca0cc2667932e2d Mon Sep 17 00:00:00 2001 From: fwsmit Date: Fri, 22 Jan 2021 23:35:06 +0100 Subject: [PATCH] examples/foreign-toplevel: Add documenation and output selection --- examples/foreign-toplevel.c | 73 +++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/examples/foreign-toplevel.c b/examples/foreign-toplevel.c index 995d4f6c..820fc07b 100644 --- a/examples/foreign-toplevel.c +++ b/examples/foreign-toplevel.c @@ -9,26 +9,27 @@ #define WLR_FOREIGN_TOPLEVEL_MANAGEMENT_VERSION 3 -/** - * Usage: - * 1. foreign-toplevel - * Prints a list of opened toplevels - * 2. foreign-toplevel -f - * Focus the toplevel with the given id - * 3. foreign-toplevel -a - * Maximize the toplevel with the given id - * 4. foreign-toplevel -u - * Unmaximize the toplevel with the given id - * 5. foreign-toplevel -i - * Minimize the toplevel with the given id - * 6. foreign-toplevel -r - * Restore(unminimize) the toplevel with the given id - * 7. foreign-toplevel -c - * Close the toplevel with the given id - * 8. foreign-toplevel -m - * Continuously print changes to the list of opened toplevels. - * Can be used together with some of the previous options. - */ + +static void print_help(void) { + static const char usage[] = + "Usage: foreign-toplevel [OPTIONS] ...\n" + "Manage and view information about toplevel windows.\n" + "\n" + " -f focus\n" + " -s fullscreen\n" + " -o select output for fullscreen toplevel to appear on. Use this\n" + " option with -s. View available outputs with wayland-info.\n" + " -S unfullscreen\n" + " -a maximize\n" + " -u unmaximize\n" + " -i minimize\n" + " -r restore(unminimize)\n" + " -c close\n" + " -m continuously print changes to the list of opened toplevels\n" + " Can be used together with some of the previous options.\n" + " -h print help message and quit\n"; + fprintf(stderr, "%s", usage); +} enum toplevel_state_field { TOPLEVEL_STATE_MAXIMIZED = (1 << 0), @@ -39,6 +40,8 @@ enum toplevel_state_field { }; 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 { char *title; @@ -94,7 +97,7 @@ static void print_toplevel(struct toplevel_v1 *toplevel, bool print_endl) { } else { printf(" no parent"); } - + if (print_endl) { printf("\n"); } @@ -271,9 +274,11 @@ struct wl_seat *seat = NULL; static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { if (strcmp(interface, wl_output_interface.name) == 0) { - struct wl_output *output = wl_registry_bind(registry, name, - &wl_output_interface, version); - wl_output_set_user_data(output, (void*)(size_t)name); // assign some ID to the output + if (name == pref_output_id) { + pref_output = wl_registry_bind(registry, name, + &wl_output_interface, version); + + } } else if (strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0) { toplevel_manager = wl_registry_bind(registry, name, @@ -324,8 +329,7 @@ int main(int argc, char **argv) { int one_shot = 1; int c; - // TODO maybe print usage with -h? - while ((c = getopt(argc, argv, "f:a:u:i:r:c:s:S:m")) != -1) { + while ((c = getopt(argc, argv, "f:a:u:i:r:c:s:S:mo:h")) != -1) { switch (c) { case 'f': focus_id = atoi(optarg); @@ -354,6 +358,17 @@ int main(int argc, char **argv) { case 'm': one_shot = 0; 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); } 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))) { zwlr_foreign_toplevel_handle_v1_unset_fullscreen(toplevel->zwlr_toplevel);