aboutsummaryrefslogtreecommitdiff
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-14 18:53:40 -0400
committerGitHub <noreply@github.com>2017-06-14 18:53:40 -0400
commit298f56353ef155f6a2ccc977c96b2ff5d971e65e (patch)
treedcb3b74f1dde93bce8657b7509662ffd7db667d0 /swaybar/bar.c
parenta5c07dde6aba87584ddb6c6a2769472a6003623a (diff)
parenteb6e38c86d2deb37cc6f378f8644c4a530fd7448 (diff)
Merge branch 'master' into server-decoration
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c87
1 files changed, 52 insertions, 35 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index abde1cc9..3412ff29 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -7,10 +7,17 @@
#include <sys/wait.h>
#include <signal.h>
#include <poll.h>
+#ifdef ENABLE_TRAY
+#include <dbus/dbus.h>
+#include "swaybar/tray/sni_watcher.h"
+#include "swaybar/tray/tray.h"
+#include "swaybar/tray/sni.h"
+#endif
#include "swaybar/ipc.h"
#include "swaybar/render.h"
#include "swaybar/config.h"
#include "swaybar/status_line.h"
+#include "swaybar/event_loop.h"
#include "swaybar/bar.h"
#include "ipc-client.h"
#include "list.h"
@@ -34,6 +41,7 @@ static void spawn_status_cmd_proc(struct bar *bar) {
close(pipefd[0]);
dup2(pipefd[1], STDOUT_FILENO);
close(pipefd[1]);
+ setpgid(bar->status_command_pid, 0);
char *const cmd[] = {
"sh",
"-c",
@@ -56,12 +64,15 @@ struct output *new_output(const char *name) {
output->window = NULL;
output->registry = NULL;
output->workspaces = create_list();
+#ifdef ENABLE_TRAY
+ output->items = create_list();
+#endif
return output;
}
static void mouse_button_notify(struct window *window, int x, int y,
uint32_t button, uint32_t state_w) {
- sway_log(L_DEBUG, "Mouse button %d clicked at %d %d %d\n", button, x, y, state_w);
+ sway_log(L_DEBUG, "Mouse button %d clicked at %d %d %d", button, x, y, state_w);
if (!state_w) {
return;
}
@@ -92,6 +103,10 @@ static void mouse_button_notify(struct window *window, int x, int y,
break;
}
}
+
+#ifdef ENABLE_TRAY
+ tray_mouse_event(clicked_output, x, y, button, state_w);
+#endif
}
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
@@ -136,6 +151,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
/* initialize bar with default values */
bar_init(bar);
+ /* Initialize event loop lists */
+ init_event_loop();
+
/* connect to sway ipc */
bar->ipc_socketfd = ipc_open_socket(socket_path);
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
@@ -178,23 +196,41 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
}
/* spawn status command */
spawn_status_cmd_proc(bar);
+
+#ifdef ENABLE_TRAY
+ init_tray(bar);
+#endif
}
-void bar_run(struct bar *bar) {
- int pfds = bar->outputs->length + 2;
- struct pollfd *pfd = malloc(pfds * sizeof(struct pollfd));
- bool dirty = true;
+bool dirty = true;
+
+static void respond_ipc(int fd, short mask, void *_bar) {
+ struct bar *bar = (struct bar *)_bar;
+ sway_log(L_DEBUG, "Got IPC event.");
+ dirty = handle_ipc_event(bar);
+}
+
+static void respond_command(int fd, short mask, void *_bar) {
+ struct bar *bar = (struct bar *)_bar;
+ dirty = handle_status_line(bar);
+}
+
+static void respond_output(int fd, short mask, void *_output) {
+ struct output *output = (struct output *)_output;
+ if (wl_display_dispatch(output->registry->display) == -1) {
+ sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
+ }
+}
- pfd[0].fd = bar->ipc_event_socketfd;
- pfd[0].events = POLLIN;
- pfd[1].fd = bar->status_read_fd;
- pfd[1].events = POLLIN;
+void bar_run(struct bar *bar) {
+ add_event(bar->ipc_event_socketfd, POLLIN, respond_ipc, bar);
+ add_event(bar->status_read_fd, POLLIN, respond_command, bar);
int i;
for (i = 0; i < bar->outputs->length; ++i) {
struct output *output = bar->outputs->items[i];
- pfd[i+2].fd = wl_display_get_fd(output->registry->display);
- pfd[i+2].events = POLLIN;
+ add_event(wl_display_get_fd(output->registry->display),
+ POLLIN, respond_output, output);
}
while (1) {
@@ -212,29 +248,10 @@ void bar_run(struct bar *bar) {
dirty = false;
- poll(pfd, pfds, -1);
-
- if (pfd[0].revents & POLLIN) {
- sway_log(L_DEBUG, "Got IPC event.");
- dirty = handle_ipc_event(bar);
- }
-
- if (bar->config->status_command && pfd[1].revents & POLLIN) {
- sway_log(L_DEBUG, "Got update from status command.");
- dirty = handle_status_line(bar);
- }
-
- // dispatch wl_display events
- for (i = 0; i < bar->outputs->length; ++i) {
- struct output *output = bar->outputs->items[i];
- if (pfd[i+2].revents & POLLIN) {
- if (wl_display_dispatch(output->registry->display) == -1) {
- sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
- }
- } else {
- wl_display_dispatch_pending(output->registry->display);
- }
- }
+ event_loop_poll();
+#ifdef ENABLE_TRAY
+ dispatch_dbus();
+#endif
}
}
@@ -274,7 +291,7 @@ static void free_outputs(list_t *outputs) {
static void terminate_status_command(pid_t pid) {
if (pid) {
// terminate status_command process
- int ret = kill(pid, SIGTERM);
+ int ret = killpg(pid, SIGTERM);
if (ret != 0) {
sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid);
} else {