Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tray D-Bus Menu #8405

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#define _SWAY_SERVER_H
#include <stdbool.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_method_v2.h>
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_output_power_management_v1.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_session_lock_v1.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_text_input_v3.h>
#include <wlr/types/wlr_xdg_shell.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those #includes seems to be a leftover from the rebase and should be dropped from the PR.

More generally, any unrelated change should be entirely dropped from the PR's commit history via rebase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can squash later the commits, once the PR is fully ready to be merged. But I'll remove these includes.

#include "config.h"
#include "list.h"
#include "sway/desktop/idle_inhibit_v1.h"
Expand Down
1 change: 1 addition & 0 deletions include/swaybar/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct swaybar {
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_shm *shm;
struct xdg_wm_base *wm_base;

struct swaybar_config *config;
struct status_line *status;
Expand Down
5 changes: 3 additions & 2 deletions include/swaybar/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

struct swaybar;
struct swaybar_output;
struct swaybar_seat;

struct swaybar_pointer {
struct wl_pointer *pointer;
Expand Down Expand Up @@ -48,8 +49,8 @@ struct swaybar_hotspot {
struct wl_list link; // swaybar_output::hotspots
int x, y, width, height;
enum hotspot_event_handling (*callback)(struct swaybar_output *output,
struct swaybar_hotspot *hotspot, double x, double y, uint32_t button,
bool released, void *data);
struct swaybar_hotspot *hotspot, struct swaybar_seat *seat, uint32_t serial,
double x, double y, uint32_t button, bool released, void *data);
void (*destroy)(void *data);
void *data;
};
Expand Down
27 changes: 27 additions & 0 deletions include/swaybar/tray/dbusmenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _SWAYBAR_TRAY_DBUSMENU_H
#define _SWAYBAR_TRAY_DBUSMENU_H

#include "swaybar/bar.h"
#include "swaybar/tray/item.h"

void swaybar_dbusmenu_open(struct swaybar_sni *sni,
struct swaybar_output *output, struct swaybar_seat *seat, uint32_t serial,
int x, int y);

bool dbusmenu_pointer_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time_, uint32_t button, uint32_t state);

bool dbusmenu_pointer_motion(struct swaybar_seat *seat, struct wl_pointer *wl_pointer,
uint32_t time_, wl_fixed_t surface_x, wl_fixed_t surface_y);

bool dbusmenu_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y);

bool dbusmenu_pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
struct wl_surface *surface);

bool dbusmenu_pointer_frame(struct swaybar_seat *data, struct wl_pointer *wl_pointer);

bool dbusmenu_pointer_axis(struct swaybar_seat *data, struct wl_pointer *wl_pointer);

#endif
2 changes: 2 additions & 0 deletions include/swaybar/tray/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct swaybar_pixmap {
struct swaybar_sni_slot {
struct wl_list link; // swaybar_sni::slots
struct swaybar_sni *sni;
int menu_id;
const char *prop;
const char *type;
void *dest;
Expand Down Expand Up @@ -48,6 +49,7 @@ struct swaybar_sni {
char *icon_theme_path; // non-standard KDE property

struct wl_list slots; // swaybar_sni_slot::link
char **menu_icon_theme_paths;
};

struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray);
Expand Down
3 changes: 3 additions & 0 deletions include/swaybar/tray/tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct swaybar_tray {

list_t *basedirs; // char *
list_t *themes; // struct swaybar_theme *

struct swaybar_dbusmenu *menu;
struct swaybar_dbusmenu_menu *menu_pointer_focus;
};

struct swaybar_tray *create_tray(struct swaybar *bar);
Expand Down
4 changes: 4 additions & 0 deletions swaybar/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"

void free_workspaces(struct wl_list *list) {
struct swaybar_workspace *ws, *tmp;
Expand Down Expand Up @@ -364,6 +365,8 @@ static void handle_global(void *data, struct wl_registry *registry,
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
bar->cursor_shape_manager = wl_registry_bind(registry, name,
&wp_cursor_shape_manager_v1_interface, 1);
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
bar->wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
}
}

Expand Down Expand Up @@ -538,6 +541,7 @@ void bar_teardown(struct swaybar *bar) {
#if HAVE_TRAY
destroy_tray(bar->tray);
#endif
xdg_wm_base_destroy(bar->wm_base);
free_outputs(&bar->outputs);
free_outputs(&bar->unused_outputs);
free_seats(&bar->seats);
Expand Down
57 changes: 53 additions & 4 deletions swaybar/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "swaybar/input.h"
#include "swaybar/ipc.h"

#if HAVE_TRAY
#include "swaybar/tray/dbusmenu.h"
#endif

void free_hotspots(struct wl_list *list) {
struct swaybar_hotspot *hotspot, *tmp;
wl_list_for_each_safe(hotspot, tmp, list, link) {
Expand Down Expand Up @@ -131,11 +135,27 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
pointer->serial = serial;
update_cursor(seat);
}

#if HAVE_TRAY
struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_enter(data, wl_pointer, serial,
surface, surface_x, surface_y)) {
return;
}
#endif
}

static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, struct wl_surface *surface) {
#if HAVE_TRAY
struct swaybar_seat *seat = data;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this line be outside of the #if HAVE_TRAY part?

apart from that, nice that you've picked it up! was subscribed on the old PR and have seen this now :)

struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_leave(data, wl_pointer, serial,
surface)) {
return;
}
#endif

seat->pointer.current = NULL;
}

Expand All @@ -144,6 +164,13 @@ static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
struct swaybar_seat *seat = data;
seat->pointer.x = wl_fixed_to_double(surface_x);
seat->pointer.y = wl_fixed_to_double(surface_y);
#if HAVE_TRAY
struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_motion(data, wl_pointer, time,
surface_x, surface_y)) {
return;
}
#endif
}

static bool check_bindings(struct swaybar *bar, uint32_t button,
Expand All @@ -160,14 +187,15 @@ static bool check_bindings(struct swaybar *bar, uint32_t button,
}

static bool process_hotspots(struct swaybar_output *output,
struct swaybar_seat *seat, uint32_t serial,
double x, double y, uint32_t button, uint32_t state) {
bool released = state == WL_POINTER_BUTTON_STATE_RELEASED;
struct swaybar_hotspot *hotspot;
wl_list_for_each(hotspot, &output->hotspots, link) {
if (x >= hotspot->x && y >= hotspot->y
&& x < hotspot->x + hotspot->width
&& y < hotspot->y + hotspot->height) {
if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, x, y,
if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, seat, serial, x, y,
button, released, hotspot->data)) {
return true;
}
Expand All @@ -180,13 +208,20 @@ static bool process_hotspots(struct swaybar_output *output,
static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
struct swaybar_seat *seat = data;
#if HAVE_TRAY
struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_button(seat, wl_pointer, serial,
time, button, state)) {
return;
}
#endif
struct swaybar_pointer *pointer = &seat->pointer;
struct swaybar_output *output = pointer->current;
if (!sway_assert(output, "button with no active output")) {
return;
}

if (process_hotspots(output, pointer->x, pointer->y, button, state)) {
if (process_hotspots(output, seat, serial, pointer->x, pointer->y, button, state)) {
return;
}

Expand Down Expand Up @@ -240,7 +275,7 @@ static void process_discrete_scroll(struct swaybar_seat *seat,
struct swaybar_output *output, struct swaybar_pointer *pointer,
uint32_t axis, wl_fixed_t value) {
uint32_t button = wl_axis_to_button(axis, value);
if (process_hotspots(output, pointer->x, pointer->y, button, WL_POINTER_BUTTON_STATE_PRESSED)) {
if (process_hotspots(output, seat, 0, pointer->x, pointer->y, button, WL_POINTER_BUTTON_STATE_PRESSED)) {
// (Currently hotspots don't do anything on release events, so no need to emit one)
return;
}
Expand Down Expand Up @@ -297,6 +332,13 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
return;
}

#if HAVE_TRAY
struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_axis(data, wl_pointer)) {
return;
}
#endif

// If there's a while since the last scroll event,
// set 'value' to zero as if to reset the "virtual scroll wheel"
if (seat->axis[axis].discrete_steps == 0 &&
Expand All @@ -313,6 +355,13 @@ static void wl_pointer_frame(void *data, struct wl_pointer *wl_pointer) {
struct swaybar_pointer *pointer = &seat->pointer;
struct swaybar_output *output = pointer->current;

#if HAVE_TRAY
struct swaybar_config *config = seat->bar->config;
if (!config->tray_hidden && dbusmenu_pointer_frame(data, wl_pointer)) {
return;
}
#endif

if (output == NULL) {
return;
}
Expand Down Expand Up @@ -420,7 +469,7 @@ static void wl_touch_up(void *data, struct wl_touch *wl_touch,
}
if (time - slot->time < 500) {
// Tap, treat it like a pointer click
process_hotspots(slot->output, slot->x, slot->y, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
process_hotspots(slot->output, seat, serial, slot->x, slot->y, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED);
// (Currently hotspots don't do anything on release events, so no need to emit one)
}
slot->output = NULL;
Expand Down
3 changes: 2 additions & 1 deletion swaybar/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ tray_files = have_tray ? [
'tray/icon.c',
'tray/item.c',
'tray/tray.c',
'tray/watcher.c'
'tray/watcher.c',
'tray/dbusmenu.c'
] : []

swaybar_deps = [
Expand Down
2 changes: 2 additions & 0 deletions swaybar/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,

static enum hotspot_event_handling block_hotspot_callback(
struct swaybar_output *output, struct swaybar_hotspot *hotspot,
struct swaybar_seat *seat, uint32_t serial,
double x, double y, uint32_t button, bool released, void *data) {
struct i3bar_block *block = data;
struct status_line *status = output->bar->status;
Expand Down Expand Up @@ -598,6 +599,7 @@ static uint32_t render_binding_mode_indicator(struct render_context *ctx,

static enum hotspot_event_handling workspace_hotspot_callback(
struct swaybar_output *output, struct swaybar_hotspot *hotspot,
struct swaybar_seat *seat, uint32_t serial,
double x, double y, uint32_t button, bool released, void *data) {
if (button != BTN_LEFT) {
return HOTSPOT_PROCESS;
Expand Down
Loading