Tray: Implement dbusmenu

Co-authored-by: Ian Fan <ianfan0@gmail.com>
Co-authored-by: Nathan Schulte <nmschulte@gmail.com>

Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
Felix Weilbach 2021-05-30 20:45:01 +02:00 committed by RogueAI
parent f686e9ad59
commit 2fd480ff1b
11 changed files with 1468 additions and 11 deletions

1367
swaybar/tray/dbusmenu.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@
#include "swaybar/config.h"
#include "swaybar/image.h"
#include "swaybar/input.h"
#include "swaybar/tray/dbusmenu.h"
#include "swaybar/tray/host.h"
#include "swaybar/tray/icon.h"
#include "swaybar/tray/item.h"
@ -333,8 +334,9 @@ void destroy_sni(struct swaybar_sni *sni) {
free(sni);
}
static void handle_click(struct swaybar_sni *sni, int x, int y,
uint32_t button, int delta) {
static void handle_click(struct swaybar_sni *sni, struct swaybar_output *output,
struct swaybar_seat *seat, uint32_t serial, int x, int y, uint32_t button,
int delta) {
const char *method = NULL;
struct tray_binding *binding = NULL;
wl_list_for_each(binding, &sni->tray->bar->config->tray_bindings, link) {
@ -365,7 +367,11 @@ static void handle_click(struct swaybar_sni *sni, int x, int y,
method = "ContextMenu";
}
if (has_prefix(method, "Scroll")) {
if (strcmp(method, "ContextMenu") == 0) {
if (sni->menu && !sni->tray->menu) {
swaybar_dbusmenu_open(sni, output, seat, serial, x, y);
}
} else if (has_prefix(method, "Scroll")) {
char dir = method[strlen("Scroll")];
char *orientation = (dir == 'U' || dir == 'D') ? "vertical" : "horizontal";
int sign = (dir == 'U' || dir == 'L') ? -1 : 1;
@ -385,6 +391,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
static enum hotspot_event_handling icon_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) {
sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data);
@ -406,7 +413,8 @@ static enum hotspot_event_handling icon_hotspot_callback(
(int) output->output_height - config->gaps.bottom - y);
sway_log(SWAY_DEBUG, "Guessing click position at (%d, %d)", global_x, global_y);
handle_click(sni, global_x, global_y, button, 1); // TODO get delta from event
// TODO get delta from event
handle_click(sni, output, seat, serial, global_x, global_y, button, 1);
return HOTSPOT_IGNORE;
} else {
sway_log(SWAY_DEBUG, "but it doesn't exist");