This commit is contained in:
Felix Weilbach 2023-07-24 16:30:40 +02:00 committed by GitHub
commit 77a02a3470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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/bar.h"
#include "swaybar/config.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 (strncmp(method, "Scroll", strlen("Scroll")) == 0) {
if (strcmp(method, "ContextMenu") == 0) {
if (sni->menu && !sni->tray->menu) {
swaybar_dbusmenu_open(sni, output, seat, serial, x, y);
}
} else if (strncmp(method, "Scroll", strlen("Scroll")) == 0) {
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");