aboutsummaryrefslogtreecommitdiffstats
path: root/swaynagbar/nagbar.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-27 01:30:35 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-08-01 22:47:54 -0400
commit72db10c2f1a1a216c50f68461a840eea3948e878 (patch)
tree8517de29e9fda0823355a44edc1b81ae2b96f69e /swaynagbar/nagbar.c
parentImplements swaynagbar (diff)
downloadsway-72db10c2f1a1a216c50f68461a840eea3948e878.tar.gz
sway-72db10c2f1a1a216c50f68461a840eea3948e878.tar.zst
sway-72db10c2f1a1a216c50f68461a840eea3948e878.zip
Support a detailed message in swaynagbar
Diffstat (limited to 'swaynagbar/nagbar.c')
-rw-r--r--swaynagbar/nagbar.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/swaynagbar/nagbar.c b/swaynagbar/nagbar.c
index 22e5aff4..9e8bbb4b 100644
--- a/swaynagbar/nagbar.c
+++ b/swaynagbar/nagbar.c
@@ -34,8 +34,11 @@ static bool terminal_execute(char *terminal, char *command) {
34static void nagbar_button_execute(struct sway_nagbar *nagbar, 34static void nagbar_button_execute(struct sway_nagbar *nagbar,
35 struct sway_nagbar_button *button) { 35 struct sway_nagbar_button *button) {
36 wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action); 36 wlr_log(WLR_DEBUG, "Executing [%s]: %s", button->text, button->action);
37 if (!button->action) { 37 if (button->type == NAGBAR_ACTION_DISMISS) {
38 nagbar->run_display = false; 38 nagbar->run_display = false;
39 } else if (button->type == NAGBAR_ACTION_EXPAND) {
40 nagbar->details.visible = !nagbar->details.visible;
41 render_frame(nagbar);
39 } else { 42 } else {
40 if (fork() == 0) { 43 if (fork() == 0) {
41 // Child process. Will be used to prevent zombie processes 44 // Child process. Will be used to prevent zombie processes
@@ -119,8 +122,58 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
119 && x < nagbutton->x + nagbutton->width 122 && x < nagbutton->x + nagbutton->width
120 && y < nagbutton->y + nagbutton->height) { 123 && y < nagbutton->y + nagbutton->height) {
121 nagbar_button_execute(nagbar, nagbutton); 124 nagbar_button_execute(nagbar, nagbutton);
125 return;
122 } 126 }
123 } 127 }
128
129 if (nagbar->details.visible &&
130 nagbar->details.total_lines != nagbar->details.visible_lines) {
131 struct sway_nagbar_button button_up = nagbar->details.button_up;
132 if (x >= button_up.x
133 && y >= button_up.y
134 && x < button_up.x + button_up.width
135 && y < button_up.y + button_up.height
136 && nagbar->details.offset > 0) {
137 nagbar->details.offset--;
138 render_frame(nagbar);
139 return;
140 }
141
142 struct sway_nagbar_button button_down = nagbar->details.button_down;
143 int bot = nagbar->details.total_lines - nagbar->details.visible_lines;
144 if (x >= button_down.x
145 && y >= button_down.y
146 && x < button_down.x + button_down.width
147 && y < button_down.y + button_down.height
148 && nagbar->details.offset < bot) {
149 nagbar->details.offset++;
150 render_frame(nagbar);
151 return;
152 }
153 }
154}
155
156static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
157 uint32_t time, uint32_t axis, wl_fixed_t value) {
158 struct sway_nagbar *nagbar = data;
159 if (!nagbar->details.visible
160 || nagbar->pointer.x < nagbar->details.x
161 || nagbar->pointer.y < nagbar->details.y
162 || nagbar->pointer.x >= nagbar->details.x + nagbar->details.width
163 || nagbar->pointer.y >= nagbar->details.y + nagbar->details.height
164 || nagbar->details.total_lines == nagbar->details.visible_lines) {
165 return;
166 }
167
168 int direction = wl_fixed_to_int(value);
169 int bot = nagbar->details.total_lines - nagbar->details.visible_lines;
170 if (direction < 0 && nagbar->details.offset > 0) {
171 nagbar->details.offset--;
172 } else if (direction > 0 && nagbar->details.offset < bot) {
173 nagbar->details.offset++;
174 }
175
176 render_frame(nagbar);
124} 177}
125 178
126static struct wl_pointer_listener pointer_listener = { 179static struct wl_pointer_listener pointer_listener = {
@@ -128,7 +181,7 @@ static struct wl_pointer_listener pointer_listener = {
128 .leave = nop, 181 .leave = nop,
129 .motion = wl_pointer_motion, 182 .motion = wl_pointer_motion,
130 .button = wl_pointer_button, 183 .button = wl_pointer_button,
131 .axis = nop, 184 .axis = wl_pointer_axis,
132 .frame = nop, 185 .frame = nop,
133 .axis_source = nop, 186 .axis_source = nop,
134 .axis_stop = nop, 187 .axis_stop = nop,
@@ -329,6 +382,9 @@ void nagbar_destroy(struct sway_nagbar *nagbar) {
329 free(button); 382 free(button);
330 } 383 }
331 list_free(nagbar->buttons); 384 list_free(nagbar->buttons);
385 free(nagbar->details.message);
386 free(nagbar->details.button_up.text);
387 free(nagbar->details.button_down.text);
332 388
333 if (nagbar->layer_surface) { 389 if (nagbar->layer_surface) {
334 zwlr_layer_surface_v1_destroy(nagbar->layer_surface); 390 zwlr_layer_surface_v1_destroy(nagbar->layer_surface);