|
|
@ -6,8 +6,8 @@
|
|
|
|
#include <wayland-cursor.h>
|
|
|
|
#include <wayland-cursor.h>
|
|
|
|
#include "log.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "swaynag/nagbar.h"
|
|
|
|
|
|
|
|
#include "swaynag/render.h"
|
|
|
|
#include "swaynag/render.h"
|
|
|
|
|
|
|
|
#include "swaynag/swaynag.h"
|
|
|
|
#include "swaynag/types.h"
|
|
|
|
#include "swaynag/types.h"
|
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
|
|
|
|
|
|
|
|
|
|
@ -32,14 +32,14 @@ static bool terminal_execute(char *terminal, char *command) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void nagbar_button_execute(struct sway_nagbar *nagbar,
|
|
|
|
static void swaynag_button_execute(struct swaynag *swaynag,
|
|
|
|
struct sway_nagbar_button *button) {
|
|
|
|
struct swaynag_button *button) {
|
|
|
|
wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action);
|
|
|
|
wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action);
|
|
|
|
if (button->type == NAGBAR_ACTION_DISMISS) {
|
|
|
|
if (button->type == SWAYNAG_ACTION_DISMISS) {
|
|
|
|
nagbar->run_display = false;
|
|
|
|
swaynag->run_display = false;
|
|
|
|
} else if (button->type == NAGBAR_ACTION_EXPAND) {
|
|
|
|
} else if (button->type == SWAYNAG_ACTION_EXPAND) {
|
|
|
|
nagbar->details.visible = !nagbar->details.visible;
|
|
|
|
swaynag->details.visible = !swaynag->details.visible;
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (fork() == 0) {
|
|
|
|
if (fork() == 0) {
|
|
|
|
// Child process. Will be used to prevent zombie processes
|
|
|
|
// Child process. Will be used to prevent zombie processes
|
|
|
@ -50,7 +50,7 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar,
|
|
|
|
if (terminal && strlen(terminal)) {
|
|
|
|
if (terminal && strlen(terminal)) {
|
|
|
|
wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal);
|
|
|
|
wlr_log(WLR_DEBUG, "Found $TERMINAL: %s", terminal);
|
|
|
|
if (!terminal_execute(terminal, button->action)) {
|
|
|
|
if (!terminal_execute(terminal, button->action)) {
|
|
|
|
nagbar_destroy(nagbar);
|
|
|
|
swaynag_destroy(swaynag);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -67,17 +67,17 @@ static void nagbar_button_execute(struct sway_nagbar *nagbar,
|
|
|
|
static void layer_surface_configure(void *data,
|
|
|
|
static void layer_surface_configure(void *data,
|
|
|
|
struct zwlr_layer_surface_v1 *surface,
|
|
|
|
struct zwlr_layer_surface_v1 *surface,
|
|
|
|
uint32_t serial, uint32_t width, uint32_t height) {
|
|
|
|
uint32_t serial, uint32_t width, uint32_t height) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
nagbar->width = width;
|
|
|
|
swaynag->width = width;
|
|
|
|
nagbar->height = height;
|
|
|
|
swaynag->height = height;
|
|
|
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
|
|
|
zwlr_layer_surface_v1_ack_configure(surface, serial);
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void layer_surface_closed(void *data,
|
|
|
|
static void layer_surface_closed(void *data,
|
|
|
|
struct zwlr_layer_surface_v1 *surface) {
|
|
|
|
struct zwlr_layer_surface_v1 *surface) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
nagbar_destroy(nagbar);
|
|
|
|
swaynag_destroy(swaynag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
|
|
|
static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
|
|
@ -88,67 +88,67 @@ static struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
|
|
|
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
|
|
|
wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
struct sway_nagbar_pointer *pointer = &nagbar->pointer;
|
|
|
|
struct swaynag_pointer *pointer = &swaynag->pointer;
|
|
|
|
wl_surface_set_buffer_scale(pointer->cursor_surface, nagbar->scale);
|
|
|
|
wl_surface_set_buffer_scale(pointer->cursor_surface, swaynag->scale);
|
|
|
|
wl_surface_attach(pointer->cursor_surface,
|
|
|
|
wl_surface_attach(pointer->cursor_surface,
|
|
|
|
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
|
|
|
|
wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
|
|
|
|
wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
|
|
|
|
wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
|
|
|
|
pointer->cursor_image->hotspot_x / nagbar->scale,
|
|
|
|
pointer->cursor_image->hotspot_x / swaynag->scale,
|
|
|
|
pointer->cursor_image->hotspot_y / nagbar->scale);
|
|
|
|
pointer->cursor_image->hotspot_y / swaynag->scale);
|
|
|
|
wl_surface_commit(pointer->cursor_surface);
|
|
|
|
wl_surface_commit(pointer->cursor_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
|
|
|
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
nagbar->pointer.x = wl_fixed_to_int(surface_x);
|
|
|
|
swaynag->pointer.x = wl_fixed_to_int(surface_x);
|
|
|
|
nagbar->pointer.y = wl_fixed_to_int(surface_y);
|
|
|
|
swaynag->pointer.y = wl_fixed_to_int(surface_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
|
|
|
|
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
|
|
|
|
if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double x = nagbar->pointer.x * nagbar->scale;
|
|
|
|
double x = swaynag->pointer.x * swaynag->scale;
|
|
|
|
double y = nagbar->pointer.y * nagbar->scale;
|
|
|
|
double y = swaynag->pointer.y * swaynag->scale;
|
|
|
|
for (int i = 0; i < nagbar->buttons->length; i++) {
|
|
|
|
for (int i = 0; i < swaynag->buttons->length; i++) {
|
|
|
|
struct sway_nagbar_button *nagbutton = nagbar->buttons->items[i];
|
|
|
|
struct swaynag_button *nagbutton = swaynag->buttons->items[i];
|
|
|
|
if (x >= nagbutton->x
|
|
|
|
if (x >= nagbutton->x
|
|
|
|
&& y >= nagbutton->y
|
|
|
|
&& y >= nagbutton->y
|
|
|
|
&& x < nagbutton->x + nagbutton->width
|
|
|
|
&& x < nagbutton->x + nagbutton->width
|
|
|
|
&& y < nagbutton->y + nagbutton->height) {
|
|
|
|
&& y < nagbutton->y + nagbutton->height) {
|
|
|
|
nagbar_button_execute(nagbar, nagbutton);
|
|
|
|
swaynag_button_execute(swaynag, nagbutton);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->details.visible &&
|
|
|
|
if (swaynag->details.visible &&
|
|
|
|
nagbar->details.total_lines != nagbar->details.visible_lines) {
|
|
|
|
swaynag->details.total_lines != swaynag->details.visible_lines) {
|
|
|
|
struct sway_nagbar_button button_up = nagbar->details.button_up;
|
|
|
|
struct swaynag_button button_up = swaynag->details.button_up;
|
|
|
|
if (x >= button_up.x
|
|
|
|
if (x >= button_up.x
|
|
|
|
&& y >= button_up.y
|
|
|
|
&& y >= button_up.y
|
|
|
|
&& x < button_up.x + button_up.width
|
|
|
|
&& x < button_up.x + button_up.width
|
|
|
|
&& y < button_up.y + button_up.height
|
|
|
|
&& y < button_up.y + button_up.height
|
|
|
|
&& nagbar->details.offset > 0) {
|
|
|
|
&& swaynag->details.offset > 0) {
|
|
|
|
nagbar->details.offset--;
|
|
|
|
swaynag->details.offset--;
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sway_nagbar_button button_down = nagbar->details.button_down;
|
|
|
|
struct swaynag_button button_down = swaynag->details.button_down;
|
|
|
|
int bot = nagbar->details.total_lines - nagbar->details.visible_lines;
|
|
|
|
int bot = swaynag->details.total_lines - swaynag->details.visible_lines;
|
|
|
|
if (x >= button_down.x
|
|
|
|
if (x >= button_down.x
|
|
|
|
&& y >= button_down.y
|
|
|
|
&& y >= button_down.y
|
|
|
|
&& x < button_down.x + button_down.width
|
|
|
|
&& x < button_down.x + button_down.width
|
|
|
|
&& y < button_down.y + button_down.height
|
|
|
|
&& y < button_down.y + button_down.height
|
|
|
|
&& nagbar->details.offset < bot) {
|
|
|
|
&& swaynag->details.offset < bot) {
|
|
|
|
nagbar->details.offset++;
|
|
|
|
swaynag->details.offset++;
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -156,25 +156,25 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value) {
|
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
if (!nagbar->details.visible
|
|
|
|
if (!swaynag->details.visible
|
|
|
|
|| nagbar->pointer.x < nagbar->details.x
|
|
|
|
|| swaynag->pointer.x < swaynag->details.x
|
|
|
|
|| nagbar->pointer.y < nagbar->details.y
|
|
|
|
|| swaynag->pointer.y < swaynag->details.y
|
|
|
|
|| nagbar->pointer.x >= nagbar->details.x + nagbar->details.width
|
|
|
|
|| swaynag->pointer.x >= swaynag->details.x + swaynag->details.width
|
|
|
|
|| nagbar->pointer.y >= nagbar->details.y + nagbar->details.height
|
|
|
|
|| swaynag->pointer.y >= swaynag->details.y + swaynag->details.height
|
|
|
|
|| nagbar->details.total_lines == nagbar->details.visible_lines) {
|
|
|
|
|| swaynag->details.total_lines == swaynag->details.visible_lines) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int direction = wl_fixed_to_int(value);
|
|
|
|
int direction = wl_fixed_to_int(value);
|
|
|
|
int bot = nagbar->details.total_lines - nagbar->details.visible_lines;
|
|
|
|
int bot = swaynag->details.total_lines - swaynag->details.visible_lines;
|
|
|
|
if (direction < 0 && nagbar->details.offset > 0) {
|
|
|
|
if (direction < 0 && swaynag->details.offset > 0) {
|
|
|
|
nagbar->details.offset--;
|
|
|
|
swaynag->details.offset--;
|
|
|
|
} else if (direction > 0 && nagbar->details.offset < bot) {
|
|
|
|
} else if (direction > 0 && swaynag->details.offset < bot) {
|
|
|
|
nagbar->details.offset++;
|
|
|
|
swaynag->details.offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wl_pointer_listener pointer_listener = {
|
|
|
|
static struct wl_pointer_listener pointer_listener = {
|
|
|
@ -191,11 +191,11 @@ static struct wl_pointer_listener pointer_listener = {
|
|
|
|
|
|
|
|
|
|
|
|
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
|
|
|
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
|
|
|
enum wl_seat_capability caps) {
|
|
|
|
enum wl_seat_capability caps) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
|
|
|
|
if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
|
|
|
|
nagbar->pointer.pointer = wl_seat_get_pointer(wl_seat);
|
|
|
|
swaynag->pointer.pointer = wl_seat_get_pointer(wl_seat);
|
|
|
|
wl_pointer_add_listener(nagbar->pointer.pointer, &pointer_listener,
|
|
|
|
wl_pointer_add_listener(swaynag->pointer.pointer, &pointer_listener,
|
|
|
|
nagbar);
|
|
|
|
swaynag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -206,9 +206,9 @@ const struct wl_seat_listener seat_listener = {
|
|
|
|
|
|
|
|
|
|
|
|
static void output_scale(void *data, struct wl_output *output,
|
|
|
|
static void output_scale(void *data, struct wl_output *output,
|
|
|
|
int32_t factor) {
|
|
|
|
int32_t factor) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
nagbar->scale = factor;
|
|
|
|
swaynag->scale = factor;
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wl_output_listener output_listener = {
|
|
|
|
static struct wl_output_listener output_listener = {
|
|
|
@ -222,27 +222,27 @@ struct output_state {
|
|
|
|
struct wl_output *wl_output;
|
|
|
|
struct wl_output *wl_output;
|
|
|
|
uint32_t wl_name;
|
|
|
|
uint32_t wl_name;
|
|
|
|
struct zxdg_output_v1 *xdg_output;
|
|
|
|
struct zxdg_output_v1 *xdg_output;
|
|
|
|
struct sway_nagbar *nagbar;
|
|
|
|
struct swaynag *swaynag;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void xdg_output_handle_name(void *data,
|
|
|
|
static void xdg_output_handle_name(void *data,
|
|
|
|
struct zxdg_output_v1 *xdg_output, const char *name) {
|
|
|
|
struct zxdg_output_v1 *xdg_output, const char *name) {
|
|
|
|
struct output_state *state = data;
|
|
|
|
struct output_state *state = data;
|
|
|
|
char *outname = state->nagbar->output.name;
|
|
|
|
char *outname = state->swaynag->output.name;
|
|
|
|
wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname);
|
|
|
|
wlr_log(WLR_DEBUG, "Checking against output %s for %s", name, outname);
|
|
|
|
if (outname && !state->nagbar->output.wl_output) {
|
|
|
|
if (outname && !state->swaynag->output.wl_output) {
|
|
|
|
wlr_log(WLR_DEBUG, "Using output %s", name);
|
|
|
|
wlr_log(WLR_DEBUG, "Using output %s", name);
|
|
|
|
state->nagbar->output.wl_output = state->wl_output;
|
|
|
|
state->swaynag->output.wl_output = state->wl_output;
|
|
|
|
state->nagbar->output.wl_name = state->wl_name;
|
|
|
|
state->swaynag->output.wl_name = state->wl_name;
|
|
|
|
wl_output_add_listener(state->nagbar->output.wl_output,
|
|
|
|
wl_output_add_listener(state->swaynag->output.wl_output,
|
|
|
|
&output_listener, state->nagbar);
|
|
|
|
&output_listener, state->swaynag);
|
|
|
|
wl_display_roundtrip(state->nagbar->display);
|
|
|
|
wl_display_roundtrip(state->swaynag->display);
|
|
|
|
zxdg_output_v1_destroy(state->xdg_output);
|
|
|
|
zxdg_output_v1_destroy(state->xdg_output);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
zxdg_output_v1_destroy(state->xdg_output);
|
|
|
|
zxdg_output_v1_destroy(state->xdg_output);
|
|
|
|
wl_output_destroy(state->wl_output);
|
|
|
|
wl_output_destroy(state->wl_output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state->nagbar->querying_outputs--;
|
|
|
|
state->swaynag->querying_outputs--;
|
|
|
|
free(state);
|
|
|
|
free(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -256,35 +256,35 @@ static struct zxdg_output_v1_listener xdg_output_listener = {
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
|
|
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
|
|
|
nagbar->compositor = wl_registry_bind(registry, name,
|
|
|
|
swaynag->compositor = wl_registry_bind(registry, name,
|
|
|
|
&wl_compositor_interface, 3);
|
|
|
|
&wl_compositor_interface, 3);
|
|
|
|
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
|
|
|
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
|
|
|
nagbar->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
|
|
|
|
swaynag->seat = wl_registry_bind(registry, name, &wl_seat_interface, 1);
|
|
|
|
wl_seat_add_listener(nagbar->seat, &seat_listener, nagbar);
|
|
|
|
wl_seat_add_listener(swaynag->seat, &seat_listener, swaynag);
|
|
|
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
|
|
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
|
|
|
nagbar->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
|
|
|
swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
|
|
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
|
|
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
|
|
|
if (!nagbar->output.wl_output && nagbar->xdg_output_manager) {
|
|
|
|
if (!swaynag->output.wl_output && swaynag->xdg_output_manager) {
|
|
|
|
nagbar->querying_outputs++;
|
|
|
|
swaynag->querying_outputs++;
|
|
|
|
struct output_state *state =
|
|
|
|
struct output_state *state =
|
|
|
|
calloc(1, sizeof(struct output_state));
|
|
|
|
calloc(1, sizeof(struct output_state));
|
|
|
|
state->nagbar = nagbar;
|
|
|
|
state->swaynag = swaynag;
|
|
|
|
state->wl_output = wl_registry_bind(registry, name,
|
|
|
|
state->wl_output = wl_registry_bind(registry, name,
|
|
|
|
&wl_output_interface, 3);
|
|
|
|
&wl_output_interface, 3);
|
|
|
|
state->wl_name = name;
|
|
|
|
state->wl_name = name;
|
|
|
|
state->xdg_output = zxdg_output_manager_v1_get_xdg_output(
|
|
|
|
state->xdg_output = zxdg_output_manager_v1_get_xdg_output(
|
|
|
|
nagbar->xdg_output_manager, state->wl_output);
|
|
|
|
swaynag->xdg_output_manager, state->wl_output);
|
|
|
|
zxdg_output_v1_add_listener(state->xdg_output,
|
|
|
|
zxdg_output_v1_add_listener(state->xdg_output,
|
|
|
|
&xdg_output_listener, state);
|
|
|
|
&xdg_output_listener, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
|
|
|
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
|
|
|
nagbar->layer_shell = wl_registry_bind(
|
|
|
|
swaynag->layer_shell = wl_registry_bind(
|
|
|
|
registry, name, &zwlr_layer_shell_v1_interface, 1);
|
|
|
|
registry, name, &zwlr_layer_shell_v1_interface, 1);
|
|
|
|
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0
|
|
|
|
} else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0
|
|
|
|
&& version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
|
|
|
|
&& version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
|
|
|
|
nagbar->xdg_output_manager = wl_registry_bind(registry, name,
|
|
|
|
swaynag->xdg_output_manager = wl_registry_bind(registry, name,
|
|
|
|
&zxdg_output_manager_v1_interface,
|
|
|
|
&zxdg_output_manager_v1_interface,
|
|
|
|
ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
|
|
|
|
ZXDG_OUTPUT_V1_NAME_SINCE_VERSION);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -292,9 +292,9 @@ static void handle_global(void *data, struct wl_registry *registry,
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
static void handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name) {
|
|
|
|
uint32_t name) {
|
|
|
|
struct sway_nagbar *nagbar = data;
|
|
|
|
struct swaynag *swaynag = data;
|
|
|
|
if (nagbar->output.wl_name == name) {
|
|
|
|
if (swaynag->output.wl_name == name) {
|
|
|
|
nagbar->run_display = false;
|
|
|
|
swaynag->run_display = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -303,110 +303,111 @@ static const struct wl_registry_listener registry_listener = {
|
|
|
|
.global_remove = handle_global_remove,
|
|
|
|
.global_remove = handle_global_remove,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void nagbar_setup(struct sway_nagbar *nagbar) {
|
|
|
|
void swaynag_setup(struct swaynag *swaynag) {
|
|
|
|
nagbar->display = wl_display_connect(NULL);
|
|
|
|
swaynag->display = wl_display_connect(NULL);
|
|
|
|
assert(nagbar->display);
|
|
|
|
assert(swaynag->display);
|
|
|
|
|
|
|
|
|
|
|
|
nagbar->scale = 1;
|
|
|
|
swaynag->scale = 1;
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_registry *registry = wl_display_get_registry(nagbar->display);
|
|
|
|
struct wl_registry *registry = wl_display_get_registry(swaynag->display);
|
|
|
|
wl_registry_add_listener(registry, ®istry_listener, nagbar);
|
|
|
|
wl_registry_add_listener(registry, ®istry_listener, swaynag);
|
|
|
|
wl_display_roundtrip(nagbar->display);
|
|
|
|
wl_display_roundtrip(swaynag->display);
|
|
|
|
assert(nagbar->compositor && nagbar->layer_shell && nagbar->shm);
|
|
|
|
assert(swaynag->compositor && swaynag->layer_shell && swaynag->shm);
|
|
|
|
|
|
|
|
|
|
|
|
while (nagbar->querying_outputs > 0) {
|
|
|
|
while (swaynag->querying_outputs > 0) {
|
|
|
|
wl_display_roundtrip(nagbar->display);
|
|
|
|
wl_display_roundtrip(swaynag->display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!nagbar->output.wl_output && nagbar->output.name) {
|
|
|
|
if (!swaynag->output.wl_output && swaynag->output.name) {
|
|
|
|
wlr_log(WLR_ERROR, "Output '%s' not found", nagbar->output.name);
|
|
|
|
wlr_log(WLR_ERROR, "Output '%s' not found", swaynag->output.name);
|
|
|
|
nagbar_destroy(nagbar);
|
|
|
|
swaynag_destroy(swaynag);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sway_nagbar_pointer *pointer = &nagbar->pointer;
|
|
|
|
struct swaynag_pointer *pointer = &swaynag->pointer;
|
|
|
|
int scale = nagbar->scale < 1 ? 1 : nagbar->scale;
|
|
|
|
int scale = swaynag->scale < 1 ? 1 : swaynag->scale;
|
|
|
|
pointer->cursor_theme = wl_cursor_theme_load(
|
|
|
|
pointer->cursor_theme = wl_cursor_theme_load(
|
|
|
|
NULL, 24 * scale, nagbar->shm);
|
|
|
|
NULL, 24 * scale, swaynag->shm);
|
|
|
|
assert(pointer->cursor_theme);
|
|
|
|
assert(pointer->cursor_theme);
|
|
|
|
struct wl_cursor *cursor =
|
|
|
|
struct wl_cursor *cursor =
|
|
|
|
wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
|
|
|
|
wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
|
|
|
|
assert(cursor);
|
|
|
|
assert(cursor);
|
|
|
|
pointer->cursor_image = cursor->images[0];
|
|
|
|
pointer->cursor_image = cursor->images[0];
|
|
|
|
pointer->cursor_surface = wl_compositor_create_surface(nagbar->compositor);
|
|
|
|
pointer->cursor_surface = wl_compositor_create_surface(swaynag->compositor);
|
|
|
|
assert(pointer->cursor_surface);
|
|
|
|
assert(pointer->cursor_surface);
|
|
|
|
|
|
|
|
|
|
|
|
nagbar->surface = wl_compositor_create_surface(nagbar->compositor);
|
|
|
|
swaynag->surface = wl_compositor_create_surface(swaynag->compositor);
|
|
|
|
assert(nagbar->surface);
|
|
|
|
assert(swaynag->surface);
|
|
|
|
nagbar->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
|
|
|
swaynag->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
|
|
|
nagbar->layer_shell, nagbar->surface, nagbar->output.wl_output,
|
|
|
|
swaynag->layer_shell, swaynag->surface, swaynag->output.wl_output,
|
|
|
|
ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag");
|
|
|
|
ZWLR_LAYER_SHELL_V1_LAYER_TOP, "swaynag");
|
|
|
|
assert(nagbar->layer_surface);
|
|
|
|
assert(swaynag->layer_surface);
|
|
|
|
zwlr_layer_surface_v1_add_listener(nagbar->layer_surface,
|
|
|
|
zwlr_layer_surface_v1_add_listener(swaynag->layer_surface,
|
|
|
|
&layer_surface_listener, nagbar);
|
|
|
|
&layer_surface_listener, swaynag);
|
|
|
|
zwlr_layer_surface_v1_set_anchor(nagbar->layer_surface, nagbar->anchors);
|
|
|
|
zwlr_layer_surface_v1_set_anchor(swaynag->layer_surface, swaynag->anchors);
|
|
|
|
|
|
|
|
|
|
|
|
wl_registry_destroy(registry);
|
|
|
|
wl_registry_destroy(registry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nagbar_run(struct sway_nagbar *nagbar) {
|
|
|
|
void swaynag_run(struct swaynag *swaynag) {
|
|
|
|
nagbar->run_display = true;
|
|
|
|
swaynag->run_display = true;
|
|
|
|
render_frame(nagbar);
|
|
|
|
render_frame(swaynag);
|
|
|
|
while (nagbar->run_display && wl_display_dispatch(nagbar->display) != -1) {
|
|
|
|
while (swaynag->run_display
|
|
|
|
|
|
|
|
&& wl_display_dispatch(swaynag->display) != -1) {
|
|
|
|
// This is intentionally left blank
|
|
|
|
// This is intentionally left blank
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void nagbar_destroy(struct sway_nagbar *nagbar) {
|
|
|
|
void swaynag_destroy(struct swaynag *swaynag) {
|
|
|
|
nagbar->run_display = false;
|
|
|
|
swaynag->run_display = false;
|
|
|
|
|
|
|
|
|
|
|
|
free(nagbar->message);
|
|
|
|
free(swaynag->message);
|
|
|
|
free(nagbar->font);
|
|
|
|
free(swaynag->font);
|
|
|
|
while (nagbar->buttons->length) {
|
|
|
|
while (swaynag->buttons->length) {
|
|
|
|
struct sway_nagbar_button *button = nagbar->buttons->items[0];
|
|
|
|
struct swaynag_button *button = swaynag->buttons->items[0];
|
|
|
|
list_del(nagbar->buttons, 0);
|
|
|
|
list_del(swaynag->buttons, 0);
|
|
|
|
free(button->text);
|
|
|
|
free(button->text);
|
|
|
|
free(button->action);
|
|
|
|
free(button->action);
|
|
|
|
free(button);
|
|
|
|
free(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_free(nagbar->buttons);
|
|
|
|
list_free(swaynag->buttons);
|
|
|
|
free(nagbar->details.message);
|
|
|
|
free(swaynag->details.message);
|
|
|
|
free(nagbar->details.button_up.text);
|
|
|
|
free(swaynag->details.button_up.text);
|
|
|
|
free(nagbar->details.button_down.text);
|
|
|
|
free(swaynag->details.button_down.text);
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->type) {
|
|
|
|
if (swaynag->type) {
|
|
|
|
nagbar_type_free(nagbar->type);
|
|
|
|
swaynag_type_free(swaynag->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->layer_surface) {
|
|
|
|
if (swaynag->layer_surface) {
|
|
|
|
zwlr_layer_surface_v1_destroy(nagbar->layer_surface);
|
|
|
|
zwlr_layer_surface_v1_destroy(swaynag->layer_surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->surface) {
|
|
|
|
if (swaynag->surface) {
|
|
|
|
wl_surface_destroy(nagbar->surface);
|
|
|
|
wl_surface_destroy(swaynag->surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->output.wl_output) {
|
|
|
|
if (swaynag->output.wl_output) {
|
|
|
|
wl_output_destroy(nagbar->output.wl_output);
|
|
|
|
wl_output_destroy(swaynag->output.wl_output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (&nagbar->buffers[0]) {
|
|
|
|
if (&swaynag->buffers[0]) {
|
|
|
|
destroy_buffer(&nagbar->buffers[0]);
|
|
|
|
destroy_buffer(&swaynag->buffers[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (&nagbar->buffers[1]) {
|
|
|
|
if (&swaynag->buffers[1]) {
|
|
|
|
destroy_buffer(&nagbar->buffers[1]);
|
|
|
|
destroy_buffer(&swaynag->buffers[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->compositor) {
|
|
|
|
if (swaynag->compositor) {
|
|
|
|
wl_compositor_destroy(nagbar->compositor);
|
|
|
|
wl_compositor_destroy(swaynag->compositor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->shm) {
|
|
|
|
if (swaynag->shm) {
|
|
|
|
wl_shm_destroy(nagbar->shm);
|
|
|
|
wl_shm_destroy(swaynag->shm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (nagbar->display) {
|
|
|
|
if (swaynag->display) {
|
|
|
|
wl_display_disconnect(nagbar->display);
|
|
|
|
wl_display_disconnect(swaynag->display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|