Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause */
7
8#include <stddef.h>
9#if defined(__linux__) || defined(__FreeBSD__)
10#include <linux/input-event-codes.h>
11#else
12#define BTN_LEFT (0x110)
13#define BTN_RIGHT (0x111)
14#define BTN_MIDDLE (0x112)
15#define BTN_TOUCH (0x14a)
16#endif
17
18#include "input.h"
19#include "log.h"
20#include "menu.h"
21#include "settings.h"
22#include "queues.h"
23
24int get_notification_clickable_height(struct notification *n, bool first, bool last)
25{
26 int notification_size = n->displayed_height;
27 if (settings.gap_size) {
28 notification_size += settings.frame_width * 2;
29 } else {
30 double half_separator = settings.separator_height / 2.0;
31 notification_size += settings.separator_height;
32 if(first)
33 notification_size += (settings.frame_width - half_separator);
34 if(last)
35 notification_size += (settings.frame_width - half_separator);
36 }
37 return notification_size;
38}
39
40struct notification *get_notification_at(const int y)
41{
42 int curr_y = 0;
43 bool first = true;
44 bool last;
45 for (const GList *iter = queues_get_displayed(); iter;
46 iter = iter->next) {
47 struct notification *current = iter->data;
48 struct notification *next = iter->next ? iter->next->data : NULL;
49
50 last = !next;
51 int notification_size = get_notification_clickable_height(current, first, last);
52
53 if (y >= curr_y && y < curr_y + notification_size) {
54 return current;
55 }
56
57 curr_y += notification_size;
58 if (settings.gap_size)
59 curr_y += settings.gap_size;
60
61 first = false;
62 }
63 // no matching notification was found
64 return NULL;
65}
66
67void input_handle_click(unsigned int button, bool button_down, int mouse_x, int mouse_y)
68{
69 LOG_I("Pointer handle button %i: %i", button, button_down);
70
71 if (button_down) {
72 // make sure it only reacts on button release
73 return;
74 }
75
76 enum mouse_action *acts;
77
78 switch (button) {
79 case BTN_LEFT:
80 acts = settings.mouse_left_click;
81 break;
82 case BTN_MIDDLE:
83 acts = settings.mouse_middle_click;
84 break;
85 case BTN_RIGHT:
86 acts = settings.mouse_right_click;
87 break;
88 case BTN_TOUCH:
89 // TODO Add separate action for touch
90 acts = settings.mouse_left_click;
91 break;
92 default:
93 LOG_W("Unsupported mouse button: '%d'", button);
94 return;
95 }
96
97 // if other list types are added, make sure they have the same end value
98 for (int i = 0; acts[i] != MOUSE_ACTION_END; i++) {
99 enum mouse_action act = acts[i];
100 if (act == MOUSE_CLOSE_ALL) {
102 continue;
103 }
104
105 if (act == MOUSE_CONTEXT_ALL) {
106 context_menu();
107 continue;
108 }
109
110 if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT || act == MOUSE_REMOVE_CURRENT || act == MOUSE_CONTEXT || act == MOUSE_OPEN_URL) {
111 struct notification *n = get_notification_at(mouse_y);
112
113 if (n) {
114 if (act == MOUSE_CLOSE_CURRENT) {
115 n->marked_for_closure = REASON_USER;
116 } else if (act == MOUSE_DO_ACTION) {
118 } else if (act == MOUSE_OPEN_URL) {
120 } else if (act == MOUSE_REMOVE_CURRENT) {
122 } else {
124 }
125 }
126 }
127 }
128
129 wake_up();
130}
@ REASON_USER
The user closed the notification.
Definition dbus.h:21
void input_handle_click(unsigned int button, bool button_down, int mouse_x, int mouse_y)
Handle incoming mouse click events.
Definition input.c:67
Input handling for mouse events.
Logging subsystem and helpers.
void context_menu(void)
Open the context menu that lets the user select urls/actions/etc for all displayed notifications.
Definition menu.c:320
Context menu for actions and helpers.
void notification_do_action(struct notification *n)
If the notification has an action named n->default_action_name or there is only one action and n->def...
void notification_open_url(struct notification *n)
If the notification has exactly one url, invoke it.
void notification_open_context_menu(struct notification *n)
Open the context menu for the notification.
GList * queues_get_displayed(void)
Receive the current list of displayed notifications.
Definition queues.c:41
void queues_history_push_all(void)
Push all waiting and displayed notifications to history.
Definition queues.c:465
Queues for history, waiting and displayed notifications.
Type definitions for settings.
guint8 marked_for_removal
If set, the notification is marked for removal in history.