From a4f7bf23b21d0d838a8a19261d5fd69719003a03 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Fri, 27 Jul 2018 11:19:42 -0400 Subject: [PATCH] Address first round review for swaynag --- include/{swaynagbar => swaynag}/nagbar.h | 0 include/{swaynagbar => swaynag}/render.h | 0 meson.build | 4 ++-- sway/desktop/layer_shell.c | 8 +++++--- {swaynagbar => swaynag}/main.c | 20 ++++++++----------- {swaynagbar => swaynag}/meson.build | 2 +- {swaynagbar => swaynag}/nagbar.c | 8 ++++---- {swaynagbar => swaynag}/render.c | 6 ++++-- .../swaynagbar.1.scd => swaynag/swaynag.1.scd | 11 +++++----- 9 files changed, 29 insertions(+), 30 deletions(-) rename include/{swaynagbar => swaynag}/nagbar.h (100%) rename include/{swaynagbar => swaynag}/render.h (100%) rename {swaynagbar => swaynag}/main.c (93%) rename {swaynagbar => swaynag}/meson.build (94%) rename {swaynagbar => swaynag}/nagbar.c (98%) rename {swaynagbar => swaynag}/render.c (99%) rename swaynagbar/swaynagbar.1.scd => swaynag/swaynag.1.scd (76%) diff --git a/include/swaynagbar/nagbar.h b/include/swaynag/nagbar.h similarity index 100% rename from include/swaynagbar/nagbar.h rename to include/swaynag/nagbar.h diff --git a/include/swaynagbar/render.h b/include/swaynag/render.h similarity index 100% rename from include/swaynagbar/render.h rename to include/swaynag/render.h diff --git a/meson.build b/meson.build index 26d36e06b..c6501c395 100644 --- a/meson.build +++ b/meson.build @@ -82,7 +82,7 @@ if scdoc.found() 'swaylock/swaylock.1.scd', 'swaymsg/swaymsg.1.scd', 'swayidle/swayidle.1.scd', - 'swaynagbar/swaynagbar.1.scd', + 'swaynag/swaynag.1.scd', ] foreach filename : man_files topic = filename.split('.')[-3].split('/')[-1] @@ -131,7 +131,7 @@ subdir('swaybg') subdir('swaybar') subdir('swaylock') subdir('swayidle') -subdir('swaynagbar') +subdir('swaynag') config = configuration_data() config.set('sysconfdir', join_paths(prefix, sysconfdir)) diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 71a0163cd..a2935883e 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -214,9 +214,6 @@ void arrange_layers(struct sway_output *output) { wl_list_for_each(seat, &input_manager->seats, link) { seat_set_focus_layer(seat, topmost ? topmost->layer_surface : NULL); } - - arrange_windows(output->swayc); - transaction_commit_dirty(); } static void handle_output_destroy(struct wl_listener *listener, void *data) { @@ -250,6 +247,9 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { output_damage_surface(output, layer->geo.x, layer->geo.y, layer_surface->surface, false); } + + arrange_windows(output->swayc); + transaction_commit_dirty(); } static void unmap(struct sway_layer_surface *sway_layer) { @@ -287,6 +287,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_output *output = sway_layer->layer_surface->output->data; if (output != NULL && output->swayc != NULL) { arrange_layers(output); + arrange_windows(output->swayc); + transaction_commit_dirty(); } wl_list_remove(&sway_layer->output_destroy.link); sway_layer->layer_surface->output = NULL; diff --git a/swaynagbar/main.c b/swaynag/main.c similarity index 93% rename from swaynagbar/main.c rename to swaynag/main.c index 389118c6e..60560c729 100644 --- a/swaynagbar/main.c +++ b/swaynag/main.c @@ -4,7 +4,7 @@ #include "log.h" #include "list.h" #include "readline.h" -#include "swaynagbar/nagbar.h" +#include "swaynag/nagbar.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" static struct sway_nagbar nagbar; @@ -71,7 +71,7 @@ int main(int argc, char **argv) { | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; nagbar.type = NAGBAR_ERROR; set_nagbar_colors(); - nagbar.font = strdup("pango:monospace 8"); + nagbar.font = strdup("pango:monospace 10"); nagbar.buttons = create_list(); struct sway_nagbar_button *button_close = @@ -91,7 +91,7 @@ int main(int argc, char **argv) { {"edge", required_argument, NULL, 'e'}, {"font", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 'h'}, - {"detailed-message", required_argument, NULL, 'l'}, + {"detailed-message", no_argument, NULL, 'l'}, {"detailed-button", required_argument, NULL, 'L'}, {"message", required_argument, NULL, 'm'}, {"output", required_argument, NULL, 'o'}, @@ -102,7 +102,7 @@ int main(int argc, char **argv) { }; const char *usage = - "Usage: swaynagbar [options...]\n" + "Usage: swaynag [options...]\n" "\n" " -b, --button Create a button with text that " "executes action when pressed. Multiple buttons can be defined.\n" @@ -110,7 +110,7 @@ int main(int argc, char **argv) { " -e, --edge top|bottom Set the edge to use.\n" " -f, --font Set the font to use.\n" " -h, --help Show help message and quit.\n" - " -l, --detailed-message Set a detailed message.\n" + " -l, --detailed-message Read a detailed message from stdin.\n" " -L, --detailed-button Set the text of the detail button.\n" " -m, --message Set the message text.\n" " -o, --output Set the output to use.\n" @@ -119,7 +119,7 @@ int main(int argc, char **argv) { " -v, --version Show the version number and quit.\n"; while (1) { - int c = getopt_long(argc, argv, "b:de:f:hl:L:m:o:s:t:v", opts, NULL); + int c = getopt_long(argc, argv, "b:de:f:hlL:m:o:s:t:v", opts, NULL); if (c == -1) { break; } @@ -162,11 +162,7 @@ int main(int argc, char **argv) { break; case 'l': // Detailed Message free(nagbar.details.message); - if (strcmp(optarg, "-") == 0) { - nagbar.details.message = read_from_stdin(); - } else { - nagbar.details.message = strdup(optarg); - } + nagbar.details.message = read_from_stdin(); nagbar.details.button_up.text = strdup("▲"); nagbar.details.button_down.text = strdup("▼"); break; @@ -199,7 +195,7 @@ int main(int argc, char **argv) { set_nagbar_colors(); break; case 'v': // Version - fprintf(stdout, "sway version " SWAY_VERSION "\n"); + fprintf(stdout, "swaynag version " SWAY_VERSION "\n"); exit_code = EXIT_SUCCESS; goto cleanup; default: // Help or unknown flag diff --git a/swaynagbar/meson.build b/swaynag/meson.build similarity index 94% rename from swaynagbar/meson.build rename to swaynag/meson.build index 254462f2e..6492e4dcb 100644 --- a/swaynagbar/meson.build +++ b/swaynag/meson.build @@ -1,5 +1,5 @@ executable( - 'swaynagbar', [ + 'swaynag', [ 'main.c', 'nagbar.c', 'render.c', diff --git a/swaynagbar/nagbar.c b/swaynag/nagbar.c similarity index 98% rename from swaynagbar/nagbar.c rename to swaynag/nagbar.c index 9e8bbb4b8..6647e8c28 100644 --- a/swaynagbar/nagbar.c +++ b/swaynag/nagbar.c @@ -6,8 +6,8 @@ #include #include "log.h" #include "list.h" -#include "swaynagbar/nagbar.h" -#include "swaynagbar/render.h" +#include "swaynag/nagbar.h" +#include "swaynag/render.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" static void nop() { @@ -15,7 +15,7 @@ static void nop() { } static bool terminal_execute(char *terminal, char *command) { - char fname[] = "/tmp/swaynagbarXXXXXX"; + char fname[] = "/tmp/swaynagXXXXXX"; FILE *tmp= fdopen(mkstemp(fname), "w"); if (!tmp) { wlr_log(WLR_ERROR, "Failed to create temp script"); @@ -352,7 +352,7 @@ void nagbar_setup(struct sway_nagbar *nagbar) { assert(nagbar->surface); nagbar->layer_surface = zwlr_layer_shell_v1_get_layer_surface( nagbar->layer_shell, nagbar->surface, nagbar->output.wl_output, - ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "nagbar"); + ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag"); assert(nagbar->layer_surface); zwlr_layer_surface_v1_add_listener(nagbar->layer_surface, &layer_surface_listener, nagbar); diff --git a/swaynagbar/render.c b/swaynag/render.c similarity index 99% rename from swaynagbar/render.c rename to swaynag/render.c index 7bc2961e4..150ae3f28 100644 --- a/swaynagbar/render.c +++ b/swaynag/render.c @@ -3,7 +3,7 @@ #include "log.h" #include "pango.h" #include "pool-buffer.h" -#include "swaynagbar/nagbar.h" +#include "swaynag/nagbar.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" static uint32_t render_message(cairo_t *cairo, struct sway_nagbar *nagbar) { @@ -274,7 +274,7 @@ void render_frame(struct sway_nagbar *nagbar) { nagbar->height * nagbar->scale); if (!nagbar->current_buffer) { wlr_log(WLR_DEBUG, "Failed to get buffer. Skipping frame."); - return; + goto cleanup; } cairo_t *shm = nagbar->current_buffer->cairo; @@ -293,6 +293,8 @@ void render_frame(struct sway_nagbar *nagbar) { wl_surface_commit(nagbar->surface); wl_display_roundtrip(nagbar->display); } + +cleanup: cairo_surface_destroy(recorder); cairo_destroy(cairo); } diff --git a/swaynagbar/swaynagbar.1.scd b/swaynag/swaynag.1.scd similarity index 76% rename from swaynagbar/swaynagbar.1.scd rename to swaynag/swaynag.1.scd index 2a34ae68d..879aaf2e7 100644 --- a/swaynagbar/swaynagbar.1.scd +++ b/swaynag/swaynag.1.scd @@ -2,11 +2,11 @@ swaynagbar(1) # NAME -swaynagbar - Show a warning or error message with buttons +swaynag - Show a warning or error message with buttons # SYNOPSIS -_swaynagbar_ [options...] +_swaynag_ [options...] # OPTIONS *-b, --button* @@ -25,10 +25,9 @@ _swaynagbar_ [options...] *-h, --help* Show help message and quit. -*-l, --detailed-message * - Set the detailed message. A button to toggle details will be added. Details - are shown in a scrollable multi-line text area. If _msg_ is _-_, then the - detailed message will be read from stdin. +*-l, --detailed-message* + Read a detailed message from stdin. A button to toggle details will be + added. Details are shown in a scrollable multi-line text area. *-L, --detailed-button * Set the text for the button that toggles details. This has no effect if