wob-0.6/0000755000175000001440000000000013604703575011032 5ustar anonuserswob-0.6/meson.build0000644000175000001440000000426013604702654013173 0ustar anonusersproject( 'wob', 'c', version: '0.6', license: 'ISC', default_options: ['c_std=c99'] ) cc = meson.get_compiler('c') wayland_protos = dependency('wayland-protocols', version: '>=1.13') wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir') wayland_scanner = find_program('wayland-scanner') wayland_client = dependency('wayland-client') rt = cc.find_library('rt') wob_version = '"@0@"'.format(meson.project_version()) add_project_arguments('-DWOB_VERSION=@0@'.format(wob_version), language: 'c') 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@'], ) client_protocols = [ [wl_protocol_dir + '/stable/xdg-shell', 'xdg-shell.xml'], [meson.source_root(), 'wlr-layer-shell-unstable-v1.xml'], ] foreach p : client_protocols xml = join_paths(p) src = wayland_scanner_code.process(xml) header = wayland_scanner_client.process(xml) name = p[1].split('.')[0].underscorify() lib = static_library( name, [src, header], dependencies: [wayland_client], ) dep = declare_dependency( link_with: lib, sources: header, ) set_variable(name, dep) endforeach executable( 'wob', 'wob.c', dependencies: [wayland_client, wlr_layer_shell_unstable_v1, xdg_shell, rt], install: true ) e = executable( 'wob-test', 'test.c', dependencies: [wayland_client, wlr_layer_shell_unstable_v1, xdg_shell, rt], c_args: ['-Wno-unused-function'] ) test('wob-test', e) scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-page')) if scdoc.found() scdoc = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true) sh = find_program('sh', native: true) mandir = get_option('mandir') scdfile = 'wob.1.scd' manfile = scdfile.split('.scd')[0] custom_target( manfile, input: scdfile, output: manfile, command: [ sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc.path(), manfile) ], install: true, install_dir: join_paths(mandir, 'man1') ) endif wob-0.6/meson_options.txt0000644000175000001440000000014013604702654014457 0ustar anonusersoption('man-page', type: 'feature', value: 'auto', description: 'Generate and install man page')wob-0.6/wob.c0000644000175000001440000004370413604702654011772 0ustar anonusers#define DEFAULT_WIDTH 400 #define DEFAULT_HEIGHT 50 #define DEFAULT_BORDER_OFFSET 4 #define DEFAULT_BORDER_SIZE 4 #define DEFAULT_BAR_PADDING 4 #define DEFAULT_ANCHOR 0 #define DEFAULT_MARGIN 0 #define MIN_PERCENTAGE_BAR_WIDTH 1 #define MIN_PERCENTAGE_BAR_HEIGHT 1 #define BLACK 0xFF000000 #define WHITE 0xFFFFFFFF // sizeof already includes NULL byte #define INPUT_BUFFER_LENGTH (3 * sizeof(unsigned long) + sizeof(" #FF000000 #FFFFFFFF #FFFFFFFF\n")) #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define _POSIX_C_SOURCE 200809L #include #include #include // shm #include #include #include // true, false #include // NULL #include // EXIT_FAILURE #include // strcmp #include // shm #include // shm, ftruncate #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "xdg-shell-client-protocol.h" typedef uint32_t argb_color; struct wob_geom { unsigned long width; unsigned long height; unsigned long border_offset; unsigned long border_size; unsigned long bar_padding; unsigned long stride; unsigned long size; unsigned long anchor; unsigned long margin; }; struct wob { struct wl_buffer *wl_buffer; struct wl_compositor *wl_compositor; struct wl_display *wl_display; struct wl_output *wl_output; struct wl_registry *wl_registry; struct wl_shm *wl_shm; struct wl_surface *wl_surface; struct xdg_wm_base *xdg_wm_base; struct zwlr_layer_shell_v1 *zwlr_layer_shell; struct zwlr_layer_surface_v1 *zwlr_layer_surface; struct wob_geom *wob_geom; int shmid; }; unsigned long pedantic_strtoul(const char *restrict str, char **restrict str_end, int base) { if (*str == '-' || *str == '+') { *str_end = (char *) str; return 0; } return strtoul(str, str_end, base); } void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t w, uint32_t h) { zwlr_layer_surface_v1_ack_configure(surface, serial); } void layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) { } void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { struct wob *app = (struct wob *) data; if (strcmp(interface, wl_shm_interface.name) == 0) { app->wl_shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); } else if (strcmp(interface, wl_compositor_interface.name) == 0) { app->wl_compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1); } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { app->xdg_wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); } else if (strcmp(interface, "wl_output") == 0) { if (!app->wl_output) { app->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1); } } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { app->zwlr_layer_shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1); } } void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { } argb_color * wob_create_argb_buffer(struct wob *app) { int shmid = -1; char shm_name[3 * sizeof(unsigned int) + sizeof("wob-")] = {0}; for (unsigned int i = 0; i < UINT_MAX; ++i) { sprintf(shm_name, "wob-%u", i); shmid = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0600); if (shmid > 0) { break; } } if (shmid < 0) { fprintf(stderr, "shm_open failed\n"); exit(EXIT_FAILURE); } shm_unlink(shm_name); if (ftruncate(shmid, app->wob_geom->size) < 0) { close(shmid); fprintf(stderr, "ftruncate failed\n"); exit(EXIT_FAILURE); } void *shm_data = mmap(NULL, app->wob_geom->size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0); if (shm_data == MAP_FAILED) { fprintf(stderr, "mmap failed\n"); exit(EXIT_FAILURE); } app->shmid = shmid; return (argb_color *) shm_data; } void wob_create_surface(struct wob *app) { const static struct wl_registry_listener wl_registry_listener = { .global = handle_global, .global_remove = handle_global_remove, }; const static struct zwlr_layer_surface_v1_listener zwlr_layer_surface_listener = { .configure = layer_surface_configure, .closed = layer_surface_closed, }; app->wl_registry = wl_display_get_registry(app->wl_display); if (app->wl_registry == NULL) { fprintf(stderr, "wl_display_get_registry failed\n"); exit(EXIT_FAILURE); } wl_registry_add_listener(app->wl_registry, &wl_registry_listener, app); if (wl_display_roundtrip(app->wl_display) == -1) { fprintf(stderr, "wl_display_roundtrip failed\n"); exit(EXIT_FAILURE); } struct wl_shm_pool *pool = wl_shm_create_pool(app->wl_shm, app->shmid, app->wob_geom->size); if (pool == NULL) { fprintf(stderr, "wl_shm_create_pool failed\n"); exit(EXIT_FAILURE); } app->wl_buffer = wl_shm_pool_create_buffer(pool, 0, app->wob_geom->width, app->wob_geom->height, app->wob_geom->stride, WL_SHM_FORMAT_ARGB8888); wl_shm_pool_destroy(pool); if (app->wl_buffer == NULL) { fprintf(stderr, "wl_shm_pool_create_buffer failed\n"); exit(EXIT_FAILURE); } app->wl_surface = wl_compositor_create_surface(app->wl_compositor); if (app->wl_surface == NULL) { fprintf(stderr, "wl_compositor_create_surface failed\n"); exit(EXIT_FAILURE); } app->zwlr_layer_surface = zwlr_layer_shell_v1_get_layer_surface(app->zwlr_layer_shell, app->wl_surface, app->wl_output, ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "wob"); if (app->zwlr_layer_surface == NULL) { fprintf(stderr, "wl_compositor_create_surface failed\n"); exit(EXIT_FAILURE); } zwlr_layer_surface_v1_set_size(app->zwlr_layer_surface, app->wob_geom->width, app->wob_geom->height); zwlr_layer_surface_v1_set_anchor(app->zwlr_layer_surface, app->wob_geom->anchor); zwlr_layer_surface_v1_set_margin(app->zwlr_layer_surface, app->wob_geom->margin, app->wob_geom->margin, app->wob_geom->margin, app->wob_geom->margin); zwlr_layer_surface_v1_add_listener(app->zwlr_layer_surface, &zwlr_layer_surface_listener, app->zwlr_layer_surface); wl_surface_commit(app->wl_surface); if (wl_display_roundtrip(app->wl_display) == -1) { fprintf(stderr, "wl_display_roundtrip failed\n"); exit(EXIT_FAILURE); } } void wob_flush(struct wob *app) { wl_surface_attach(app->wl_surface, app->wl_buffer, 0, 0); wl_surface_damage(app->wl_surface, 0, 0, app->wob_geom->width, app->wob_geom->height); wl_surface_commit(app->wl_surface); if (wl_display_dispatch(app->wl_display) == -1) { fprintf(stderr, "wl_display_dispatch failed\n"); exit(EXIT_FAILURE); } } void wob_destroy_surface(struct wob *app) { if (app->wl_registry == NULL) { return; } zwlr_layer_surface_v1_destroy(app->zwlr_layer_surface); zwlr_layer_shell_v1_destroy(app->zwlr_layer_shell); wl_surface_destroy(app->wl_surface); wl_registry_destroy(app->wl_registry); xdg_wm_base_destroy(app->xdg_wm_base); wl_buffer_destroy(app->wl_buffer); wl_compositor_destroy(app->wl_compositor); wl_shm_destroy(app->wl_shm); wl_output_destroy(app->wl_output); app->wl_buffer = NULL; app->wl_compositor = NULL; app->wl_output = NULL; app->wl_registry = NULL; app->wl_shm = NULL; app->wl_surface = NULL; app->xdg_wm_base = NULL; app->zwlr_layer_shell = NULL; app->zwlr_layer_surface = NULL; if (wl_display_roundtrip(app->wl_display) == -1) { fprintf(stderr, "wl_display_roundtrip failed\n"); exit(EXIT_FAILURE); } } void wob_destroy(struct wob *app) { wob_destroy_surface(app); wl_display_disconnect(app->wl_display); } /* Input format: percentage bgColor borderColor barColor 25 #FF000000 #FFFFFFFF #FFFFFFFF */ bool wob_parse_input(const char *input_buffer, unsigned long *percentage, argb_color *background_color, argb_color *border_color, argb_color *bar_color) { char *input_ptr, *newline_position; newline_position = strchr(input_buffer, '\n'); if (newline_position == NULL) { return false; } if (newline_position == input_buffer) { return false; } *percentage = pedantic_strtoul(input_buffer, &input_ptr, 10); if (input_ptr == newline_position) { return true; } if (input_ptr + 10 > newline_position || input_ptr[0] != ' ' || input_ptr[1] != '#') { return false; } input_ptr += 2; *background_color = pedantic_strtoul(input_ptr, &input_ptr, 16); if (input_ptr + 10 > newline_position || input_ptr[0] != ' ' || input_ptr[1] != '#') { return false; } input_ptr += 2; *border_color = pedantic_strtoul(input_ptr, &input_ptr, 16); if (input_ptr + 10 > newline_position || input_ptr[0] != ' ' || input_ptr[1] != '#') { return false; } input_ptr += 2; *bar_color = pedantic_strtoul(input_ptr, &input_ptr, 16); if (*input_ptr != '\n') { return false; } return true; } void wob_draw_background(const struct wob_geom *geom, argb_color *argb, argb_color color) { for (size_t i = 0; i < geom->width * geom->height; ++i) { argb[i] = color; } } void wob_draw_border(const struct wob_geom *geom, argb_color *argb, argb_color color) { // create top and bottom line size_t i = geom->width * geom->border_offset; size_t k = geom->width * (geom->height - geom->border_offset - geom->border_size); for (size_t line = 0; line < geom->border_size; ++line) { i += geom->border_offset; k += geom->border_offset; for (size_t pixel = 0; pixel < geom->width - 2 * geom->border_offset; ++pixel) { argb[i++] = color; argb[k++] = color; } i += geom->border_offset; k += geom->border_offset; } // create left and right horizontal line i = geom->width * (geom->border_offset + geom->border_size); k = geom->width * (geom->border_offset + geom->border_size); for (size_t line = 0; line < geom->height - 2 * (geom->border_size + geom->border_offset); ++line) { i += geom->border_offset; k += geom->width - geom->border_offset - geom->border_size; for (size_t pixel = 0; pixel < geom->border_size; ++pixel) { argb[i++] = color; argb[k++] = color; } i += geom->width - geom->border_offset - geom->border_size; k += geom->border_offset; } } void wob_draw_percentage(const struct wob_geom *geom, argb_color *argb, argb_color bar_color, argb_color background_color, unsigned long percentage, unsigned long maximum) { size_t offset_border_padding = geom->border_offset + geom->border_size + geom->bar_padding; size_t bar_width = geom->width - 2 * offset_border_padding; size_t bar_height = geom->height - 2 * offset_border_padding; size_t bar_colored_width = (bar_width * percentage) / maximum; // draw 1px horizontal line argb_color *start, *end, *pixel; start = &argb[offset_border_padding * (geom->width + 1)]; end = start + bar_colored_width; for (pixel = start; pixel < end; ++pixel) { *pixel = bar_color; } for (end = start + bar_width; pixel < end; ++pixel) { *pixel = background_color; } // copy it to make full percentage bar argb_color *source = &argb[offset_border_padding * geom->width]; argb_color *destination = source + geom->width; end = &argb[geom->width * (bar_height + offset_border_padding)]; while (destination != end) { memcpy(destination, source, MIN(destination - source, end - destination) * sizeof(argb_color)); destination += MIN(destination - source, end - destination); } } #ifndef WOB_TEST int main(int argc, char **argv) { const char *usage = "Usage: wob [options]\n" "\n" " -h Show help message and quit.\n" " -v Show the version number and quit.\n" " -t Hide wob after milliseconds, defaults to 1000.\n" " -m <%> Define the maximum percentage, defaults to 100. \n" " -W Define display width in pixels, defaults to 400. \n" " -H Define display height in pixels, defaults to 50. \n" " -o Define border offset in pixels, defaults to 4. \n" " -b Define border size in pixels, defaults to 4. \n" " -p Define bar padding in pixels, defaults to 4. \n" " -a Define anchor point; one of 'top', 'left', 'right', 'bottom', 'center' (default). \n" " May be specified multiple times. \n" " -M Define anchor margin in pixels, defaults to 0. \n" "\n"; struct wob app = {0}; app.wl_display = wl_display_connect(NULL); assert(app.wl_display); if (app.wl_display == NULL) { fprintf(stderr, "wl_display_connect failed\n"); return EXIT_FAILURE; } // Parse arguments int c; unsigned long maximum = 100; unsigned long timeout_msec = 1000; struct wob_geom geom = { .width = DEFAULT_WIDTH, .height = DEFAULT_HEIGHT, .border_offset = DEFAULT_BORDER_OFFSET, .border_size = DEFAULT_BORDER_SIZE, .bar_padding = DEFAULT_BAR_PADDING, .anchor = DEFAULT_ANCHOR, .margin = DEFAULT_MARGIN, }; char *strtoul_end; while ((c = getopt(argc, argv, "t:m:W:H:o:b:p:a:M:vh")) != -1) { switch (c) { case 't': timeout_msec = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE || timeout_msec == 0) { fprintf(stderr, "Timeout must be a value between 1 and %lu.\n", ULONG_MAX); return EXIT_FAILURE; } break; case 'm': maximum = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE || maximum == 0) { fprintf(stderr, "Maximum must be a value between 1 and %lu.\n", ULONG_MAX); return EXIT_FAILURE; } break; case 'W': geom.width = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Width must be a positive value."); return EXIT_FAILURE; } break; case 'H': geom.height = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Height must be a positive value."); return EXIT_FAILURE; } break; case 'o': geom.border_offset = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Border offset must be a positive value."); return EXIT_FAILURE; } break; case 'b': geom.border_size = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Border size must be a positive value."); return EXIT_FAILURE; } break; case 'p': geom.bar_padding = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Bar padding must be a positive value."); return EXIT_FAILURE; } break; case 'a': if (strcmp(optarg, "left") == 0) { geom.anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; } else if (strcmp(optarg, "right") == 0) { geom.anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; } else if (strcmp(optarg, "top") == 0) { geom.anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; } else if (strcmp(optarg, "bottom") == 0) { geom.anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; } else if (strcmp(optarg, "center") != 0) { fprintf(stderr, "Anchor must be one of 'top', 'bottom', 'left', 'right', 'center'."); return EXIT_FAILURE; } break; case 'M': geom.margin = pedantic_strtoul(optarg, &strtoul_end, 10); if (*strtoul_end != '\0' || errno == ERANGE) { fprintf(stderr, "Anchor margin must be a positive value."); return EXIT_FAILURE; } break; case 'v': fprintf(stdout, "wob version: " WOB_VERSION "\n"); return EXIT_SUCCESS; case 'h': fprintf(stdout, "%s", usage); return EXIT_SUCCESS; default: fprintf(stderr, "%s", usage); return EXIT_FAILURE; } } if (geom.width < MIN_PERCENTAGE_BAR_WIDTH + 2 * (geom.border_offset + geom.border_size + geom.bar_padding)) { fprintf(stderr, "Invalid geometry: width is too small for given parameters\n"); return EXIT_FAILURE; } if (geom.height < MIN_PERCENTAGE_BAR_HEIGHT + 2 * (geom.border_offset + geom.border_size + geom.bar_padding)) { fprintf(stderr, "Invalid geometry: height is too small for given parameters\n"); return EXIT_FAILURE; } geom.stride = geom.width * 4; geom.size = geom.stride * geom.height; app.wob_geom = &geom; argb_color *argb = wob_create_argb_buffer(&app); assert(argb); assert(app.shmid); argb_color background_color = BLACK; argb_color bar_color = WHITE; argb_color border_color = WHITE; // Draw these at least once wob_draw_background(app.wob_geom, argb, background_color); wob_draw_border(app.wob_geom, argb, border_color); struct pollfd fds[2] = { { .fd = wl_display_get_fd(app.wl_display), .events = POLLIN, }, { .fd = STDIN_FILENO, .events = POLLIN, }, }; argb_color old_background_color, old_border_color; bool hidden = true; for (;;) { unsigned long percentage = 0; char input_buffer[INPUT_BUFFER_LENGTH] = {0}; char *fgets_rv; switch (poll(fds, 2, hidden ? -1 : timeout_msec)) { case -1: perror("poll"); wob_destroy(&app); return EXIT_FAILURE; case 0: if (!hidden) { wob_destroy_surface(&app); } hidden = true; break; default: if (fds[0].revents & POLLIN) { if (wl_display_dispatch(app.wl_display) == -1) { wob_destroy(&app); return EXIT_FAILURE; } } if (!(fds[1].revents & POLLIN)) { break; } fgets_rv = fgets(input_buffer, INPUT_BUFFER_LENGTH, stdin); if (feof(stdin)) { wob_destroy(&app); return EXIT_SUCCESS; } old_background_color = background_color; old_border_color = border_color; if (fgets_rv == NULL || !wob_parse_input(input_buffer, &percentage, &background_color, &border_color, &bar_color) || percentage > maximum) { fprintf(stderr, "Received invalid input\n"); wob_destroy(&app); return EXIT_FAILURE; } if (hidden) { wob_create_surface(&app); assert(app.wl_buffer); assert(app.wl_compositor); assert(app.wl_output); assert(app.wl_registry); assert(app.wl_shm); assert(app.wl_surface); assert(app.xdg_wm_base); assert(app.zwlr_layer_shell); assert(app.zwlr_layer_surface); } if (old_background_color != background_color || old_border_color != border_color) { wob_draw_background(app.wob_geom, argb, background_color); wob_draw_border(app.wob_geom, argb, border_color); } wob_draw_percentage(app.wob_geom, argb, bar_color, background_color, percentage, maximum); wob_flush(&app); hidden = false; break; } } } #endif wob-0.6/LICENSE0000644000175000001440000000135013604702654012033 0ustar anonusersISC License Copyright (c) 2019, Martin Franc Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 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. wob-0.6/wlr-layer-shell-unstable-v1.xml0000644000175000001440000003325113604702654016737 0ustar anonusers Copyright © 2017 Drew DeVault 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. Clients can use this interface to assign the surface_layer role to wl_surfaces. Such surfaces are assigned to a "layer" of the output and rendered with a defined z-depth respective to each other. They may also be anchored to the edges and corners of a screen and specify input handling semantics. This interface should be suitable for the implementation of many desktop shell components, and a broad number of other applications that interact with the desktop. Create a layer surface for an existing surface. This assigns the role of layer_surface, or raises a protocol error if another role is already assigned. Creating a layer surface from a wl_surface which has a buffer attached or committed is a client error, and any attempts by a client to attach or manipulate a buffer prior to the first layer_surface.configure call must also be treated as errors. You may pass NULL for output to allow the compositor to decide which output to use. Generally this will be the one that the user most recently interacted with. Clients can specify a namespace that defines the purpose of the layer surface. These values indicate which layers a surface can be rendered in. They are ordered by z depth, bottom-most first. Traditional shell surfaces will typically be rendered between the bottom and top layers. Fullscreen shell surfaces are typically rendered at the top layer. Multiple surfaces can share a single layer, and ordering within a single layer is undefined. An interface that may be implemented by a wl_surface, for surfaces that are designed to be rendered as a layer of a stacked desktop-like environment. Layer surface state (layer, size, anchor, exclusive zone, margin, interactivity) is double-buffered, and will be applied at the time wl_surface.commit of the corresponding wl_surface is called. Sets the size of the surface in surface-local coordinates. The compositor will display the surface centered with respect to its anchors. If you pass 0 for either value, the compositor will assign it and inform you of the assignment in the configure event. You must set your anchor to opposite edges in the dimensions you omit; not doing so is a protocol error. Both values are 0 by default. Size is double-buffered, see wl_surface.commit. Requests that the compositor anchor the surface to the specified edges and corners. If two orthogonal edges are specified (e.g. 'top' and 'left'), then the anchor point will be the intersection of the edges (e.g. the top left corner of the output); otherwise the anchor point will be centered on that edge, or in the center if none is specified. Anchor is double-buffered, see wl_surface.commit. Requests that the compositor avoids occluding an area with other surfaces. The compositor's use of this information is implementation-dependent - do not assume that this region will not actually be occluded. A positive value is only meaningful if the surface is anchored to one edge or an edge and both perpendicular edges. If the surface is not anchored, anchored to only two perpendicular edges (a corner), anchored to only two parallel edges or anchored to all edges, a positive value will be treated the same as zero. A positive zone is the distance from the edge in surface-local coordinates to consider exclusive. Surfaces that do not wish to have an exclusive zone may instead specify how they should interact with surfaces that do. If set to zero, the surface indicates that it would like to be moved to avoid occluding surfaces with a positive exclusive zone. If set to -1, the surface indicates that it would not like to be moved to accommodate for other surfaces, and the compositor should extend it all the way to the edges it is anchored to. For example, a panel might set its exclusive zone to 10, so that maximized shell surfaces are not shown on top of it. A notification might set its exclusive zone to 0, so that it is moved to avoid occluding the panel, but shell surfaces are shown underneath it. A wallpaper or lock screen might set their exclusive zone to -1, so that they stretch below or over the panel. The default value is 0. Exclusive zone is double-buffered, see wl_surface.commit. Requests that the surface be placed some distance away from the anchor point on the output, in surface-local coordinates. Setting this value for edges you are not anchored to has no effect. The exclusive zone includes the margin. Margin is double-buffered, see wl_surface.commit. Set to 1 to request that the seat send keyboard events to this layer surface. For layers below the shell surface layer, the seat will use normal focus semantics. For layers above the shell surface layers, the seat will always give exclusive keyboard focus to the top-most layer which has keyboard interactivity set to true. Layer surfaces receive pointer, touch, and tablet events normally. If you do not want to receive them, set the input region on your surface to an empty region. Events is double-buffered, see wl_surface.commit. This assigns an xdg_popup's parent to this layer_surface. This popup should have been created via xdg_surface::get_popup with the parent set to NULL, and this request must be invoked before committing the popup's initial state. See the documentation of xdg_popup for more details about what an xdg_popup is and how it is used. When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. This request destroys the layer surface. The configure event asks the client to resize its surface. Clients should arrange their surface for the new states, and then send an ack_configure request with the serial sent in this configure event at some point before committing the new surface. The client is free to dismiss all but the last configure event it received. The width and height arguments specify the size of the window in surface-local coordinates. The size is a hint, in the sense that the client is free to ignore it if it doesn't resize, pick a smaller size (to satisfy aspect ratio or resize in steps of NxM pixels). If the client picks a smaller size and is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the surface will be centered on this axis. If the width or height arguments are zero, it means the client should decide its own window dimension. The closed event is sent by the compositor when the surface will no longer be shown. The output may have been destroyed or the user may have asked for it to be removed. Further changes to the surface will be ignored. The client should destroy the resource after receiving this event, and create a new surface if they so choose. Change the layer that the surface is rendered on. Layer is double-buffered, see wl_surface.commit. wob-0.6/test.c0000644000175000001440000000215713604702654012157 0ustar anonusers#define WOB_TEST #include "wob.c" int main(int argc, char **argv) { unsigned long percentage; argb_color background_color; argb_color border_color; argb_color bar_color; char *input; bool result; printf("running 1\n"); input = "25 #FF000000 #FFFFFFFF #FFFFFFFF\n"; result = wob_parse_input(input, &percentage, &background_color, &border_color, &bar_color); if (!result || percentage != 25 || background_color != 0xFF000000 || border_color != 0xFFFFFFFF || bar_color != 0xFFFFFFFF) { return EXIT_FAILURE; } printf("running 2\n"); input = "25 #FF000000\n"; result = wob_parse_input(input, &percentage, &background_color, &border_color, &bar_color); if (result) { return EXIT_FAILURE; } printf("running 3\n"); input = "25\n"; result = wob_parse_input(input, &percentage, &background_color, &border_color, &bar_color); if (!result || percentage != 25) { return EXIT_FAILURE; } printf("running 4\n"); input = "25 #FF000000 #FFFFFFFF #FFFFFFFF \n"; result = wob_parse_input(input, &percentage, &background_color, &border_color, &bar_color); if (result) { return EXIT_FAILURE; } return EXIT_SUCCESS; }wob-0.6/wob.1.scd0000644000175000001440000000531313604702654012452 0ustar anonuserswob(1) # NAME wob - Wayland Overlay Bar # DESCRIPTION wob is a lightweight overlay volume/backlight/progress/anything bar for Wayland. # SYNOPSIS *wob* [options...] # OPTIONS *-h* Show help message and quit. *-v* Show the version number and quit. *-t* Hide wob after milliseconds, defaults to 1000. *-m* <%> Define the maximum percentage, defaults to 100. *-W* Define bar width in pixels, defaults to 400. *-H* Define bar height in pixels, defaults to 50. *-o* Define border offset in pixels, defaults to 4. *-b* Define border size in pixels, defaults to 4. *-p* Define bar padding in pixels, defaults to 4. *-a* Define anchor point, one of 'top', 'left', 'right', 'bottom', 'center' (default). May be specified multiple times. *-M* Define anchor margin in pixels, defaults to 0. # USAGE Launch wob in a terminal, enter a value (positive integer), press return. ## General case You may manage a bar for audio volume, backlight intensity, or whatever, using a named pipe. Create a named pipe, e.g. /tmp/wobpipe, on your filesystem using. ``` mkfifo /tmp/wobpipe ``` Connect the named pipe to the standard input of an wob instance. ``` tail -f /tmp/wobpipe | wob ``` Set up your environment so that after updating audio volume, backlight intensity, or whatever, to a new value like 43, it writes that value into the pipe: ``` echo 43 > /tmp/wobpipe ``` Adapt this use-case to your workflow (scripts, callbacks, or keybindings handled by the window manager). ## Sway WM example Add these lines to your Sway config file: ``` exec mkfifo $SWAYSOCK.wob && tail -f $SWAYSOCK.wob | wob ``` Volume using alsa: ``` bindsym XF86AudioRaiseVolume exec amixer -q set Master 2%+ unmute && amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print substr($2, 0, length($2)-1) }' > $SWAYSOCK.wob++ bindsym XF86AudioLowerVolume exec amixer -q set Master 2%- unmute && amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print substr($2, 0, length($2)-1) }' > $SWAYSOCK.wob++ bindsym XF86AudioMute exec (amixer get Master | grep off > /dev/null && amixer -q set Master unmute && amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print substr($2, 0, length($2)-1) }' > $SWAYSOCK.wob) || (amixer -q set Master mute && echo 0 > $SWAYSOCK.wob) ``` Volume using pulse audio: ``` bindsym XF86AudioRaiseVolume exec pamixer -ui 2 && pamixer --get-volume > $SWAYSOCK.wob++ bindsym XF86AudioLowerVolume exec pamixer -ud 2 && pamixer --get-volume > $SWAYSOCK.wob ``` Brightness using haikarainen/light: ``` bindsym XF86MonBrightnessUp exec light -A 5 && light -G | cut -d'.' -f1 > $SWAYSOCK.wob++ bindsym XF86MonBrightnessDown exec light -U 5 && light -G | cut -d'.' -f1 > $SWAYSOCK.wob ```