aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/main.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 10:58:18 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-29 10:58:18 -0500
commit60e76cf932e7b4d240af1f994a868e9f587c056d (patch)
treeb5d634bd193ee35993c93a59e15cf8e864f78908 /swaybar/main.c
parentAdd swaybar subproject (diff)
downloadsway-60e76cf932e7b4d240af1f994a868e9f587c056d.tar.gz
sway-60e76cf932e7b4d240af1f994a868e9f587c056d.tar.zst
sway-60e76cf932e7b4d240af1f994a868e9f587c056d.zip
Add swaybar basics
This should make the bar open and appear as the panel, once sway supports panels. Right now it crashes sway!
Diffstat (limited to 'swaybar/main.c')
-rw-r--r--swaybar/main.c97
1 files changed, 96 insertions, 1 deletions
diff --git a/swaybar/main.c b/swaybar/main.c
index 49ba7a78..dfdda9ca 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -4,8 +4,57 @@
4#include "client/window.h" 4#include "client/window.h"
5#include "log.h" 5#include "log.h"
6 6
7struct box_colors {
8 uint32_t border;
9 uint32_t background;
10 uint32_t text;
11};
12
13struct colors {
14 uint32_t background;
15 uint32_t statusline;
16 uint32_t seperator;
17
18 struct box_colors focused_workspace;
19 struct box_colors active_workspace;
20 struct box_colors inactive_workspace;
21 struct box_colors urgent_workspace;
22 struct box_colors binding_mode;
23};
24
7struct registry *registry; 25struct registry *registry;
8struct window *window; 26struct window *window;
27struct colors colors = {
28 .background = 0x00000000,
29 .statusline = 0xffffffff,
30 .seperator = 0x666666ff,
31
32 .focused_workspace = {
33 .border = 0x4c7899ff,
34 .background = 0x285577ff,
35 .text = 0xffffffff
36 },
37 .active_workspace = {
38 .border = 0x333333ff,
39 .background = 0x5f676aff,
40 .text = 0xffffffff
41 },
42 .inactive_workspace = {
43 .border = 0x333333ff,
44 .background = 0x222222ff,
45 .text = 0x888888ff
46 },
47 .urgent_workspace = {
48 .border = 0x2f343aff,
49 .background = 0x900000ff,
50 .text = 0xffffffff
51 },
52 .binding_mode = {
53 .border = 0x2f343aff,
54 .background = 0x900000ff,
55 .text = 0xffffffff
56 },
57};
9 58
10void sway_terminate(void) { 59void sway_terminate(void) {
11 window_teardown(window); 60 window_teardown(window);
@@ -13,8 +62,54 @@ void sway_terminate(void) {
13 exit(EXIT_FAILURE); 62 exit(EXIT_FAILURE);
14} 63}
15 64
65void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
66 cairo_set_source_rgba(cairo,
67 ((color & 0xFF000000) >> 24) / 256.0,
68 ((color & 0xFF0000) >> 16) / 256.0,
69 ((color & 0xFF00) >> 8) / 256.0,
70 (color & 0xFF) / 256.0);
71}
72
73void render() {
74 // Reset buffer
75 cairo_save(window->cairo);
76 cairo_set_operator(window->cairo, CAIRO_OPERATOR_CLEAR);
77 cairo_paint(window->cairo);
78 cairo_restore(window->cairo);
79
80 // Draw bar
81 cairo_set_source_u32(window->cairo, colors.background);
82 cairo_paint(window->cairo);
83}
84
16int main(int argc, char **argv) { 85int main(int argc, char **argv) {
17 init_log(L_INFO); 86 init_log(L_INFO);
18 sway_log(L_INFO, "Hello world!"); 87 registry = registry_poll();
88
89 if (!registry->desktop_shell) {
90 sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
91 }
92
93 int desired_output = atoi(argv[1]);
94 sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
95
96 struct output_state *output = registry->outputs->items[desired_output];
97 window = window_setup(registry, output->width, 30, false);
98 if (!window) {
99 sway_abort("Failed to create window.");
100 }
101 desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface);
102 desktop_shell_set_panel_position(registry->desktop_shell, DESKTOP_SHELL_PANEL_POSITION_BOTTOM);
103
104 do {
105 if (window_prerender(window) && window->cairo) {
106 render();
107 window_render(window);
108 }
109 } while (wl_display_dispatch(registry->display) != -1);
110
111 window_teardown(window);
112 registry_teardown(registry);
113
19 return 0; 114 return 0;
20} 115}