2015-11-29 15:26:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "client/registry.h"
|
|
|
|
#include "client/window.h"
|
2015-11-29 20:27:28 +00:00
|
|
|
#include "client/pango.h"
|
2015-11-29 15:26:50 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
2015-11-29 20:27:28 +00:00
|
|
|
#define MARGIN 5
|
|
|
|
|
2015-11-29 15:58:18 +00:00
|
|
|
struct box_colors {
|
|
|
|
uint32_t border;
|
|
|
|
uint32_t background;
|
|
|
|
uint32_t text;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct colors {
|
|
|
|
uint32_t background;
|
|
|
|
uint32_t statusline;
|
|
|
|
uint32_t seperator;
|
|
|
|
|
|
|
|
struct box_colors focused_workspace;
|
|
|
|
struct box_colors active_workspace;
|
|
|
|
struct box_colors inactive_workspace;
|
|
|
|
struct box_colors urgent_workspace;
|
|
|
|
struct box_colors binding_mode;
|
|
|
|
};
|
|
|
|
|
2015-11-29 15:26:50 +00:00
|
|
|
struct registry *registry;
|
|
|
|
struct window *window;
|
2015-11-29 15:58:18 +00:00
|
|
|
struct colors colors = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.background = 0x000000FF,
|
|
|
|
.statusline = 0xFFFFFFFF,
|
|
|
|
.seperator = 0x666666FF,
|
2015-11-29 15:58:18 +00:00
|
|
|
|
|
|
|
.focused_workspace = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.border = 0x4C7899FF,
|
|
|
|
.background = 0x285577FF,
|
|
|
|
.text = 0xFFFFFFFF
|
2015-11-29 15:58:18 +00:00
|
|
|
},
|
|
|
|
.active_workspace = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.border = 0x333333FF,
|
|
|
|
.background = 0x5F676AFF,
|
|
|
|
.text = 0xFFFFFFFF
|
2015-11-29 15:58:18 +00:00
|
|
|
},
|
|
|
|
.inactive_workspace = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.border = 0x333333FF,
|
|
|
|
.background = 0x222222FF,
|
|
|
|
.text = 0x888888FF
|
2015-11-29 15:58:18 +00:00
|
|
|
},
|
|
|
|
.urgent_workspace = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.border = 0x2F343AFF,
|
|
|
|
.background = 0x900000FF,
|
|
|
|
.text = 0xFFFFFFFF
|
2015-11-29 15:58:18 +00:00
|
|
|
},
|
|
|
|
.binding_mode = {
|
2015-11-29 17:03:13 +00:00
|
|
|
.border = 0x2F343AFF,
|
|
|
|
.background = 0x900000FF,
|
|
|
|
.text = 0xFFFFFFFF
|
2015-11-29 15:58:18 +00:00
|
|
|
},
|
|
|
|
};
|
2015-11-29 15:26:50 +00:00
|
|
|
|
|
|
|
void sway_terminate(void) {
|
|
|
|
window_teardown(window);
|
|
|
|
registry_teardown(registry);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-11-29 15:58:18 +00:00
|
|
|
void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
|
|
|
|
cairo_set_source_rgba(cairo,
|
|
|
|
((color & 0xFF000000) >> 24) / 256.0,
|
|
|
|
((color & 0xFF0000) >> 16) / 256.0,
|
|
|
|
((color & 0xFF00) >> 8) / 256.0,
|
|
|
|
(color & 0xFF) / 256.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void render() {
|
|
|
|
cairo_save(window->cairo);
|
|
|
|
cairo_set_operator(window->cairo, CAIRO_OPERATOR_CLEAR);
|
|
|
|
cairo_paint(window->cairo);
|
|
|
|
cairo_restore(window->cairo);
|
|
|
|
|
|
|
|
cairo_set_source_u32(window->cairo, colors.background);
|
|
|
|
cairo_paint(window->cairo);
|
2015-11-29 20:27:28 +00:00
|
|
|
|
|
|
|
cairo_move_to(window->cairo, MARGIN, MARGIN);
|
|
|
|
cairo_set_source_u32(window->cairo, colors.statusline);
|
|
|
|
pango_printf(window, "TODO: finish bar");
|
2015-11-29 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 15:26:50 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
init_log(L_INFO);
|
2015-11-29 15:58:18 +00:00
|
|
|
registry = registry_poll();
|
|
|
|
|
|
|
|
if (!registry->desktop_shell) {
|
|
|
|
sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
|
|
|
|
}
|
|
|
|
|
|
|
|
int desired_output = atoi(argv[1]);
|
|
|
|
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
|
|
|
|
|
|
|
|
struct output_state *output = registry->outputs->items[desired_output];
|
|
|
|
window = window_setup(registry, output->width, 30, false);
|
|
|
|
if (!window) {
|
|
|
|
sway_abort("Failed to create window.");
|
|
|
|
}
|
|
|
|
desktop_shell_set_panel(registry->desktop_shell, output->output, window->surface);
|
|
|
|
desktop_shell_set_panel_position(registry->desktop_shell, DESKTOP_SHELL_PANEL_POSITION_BOTTOM);
|
|
|
|
|
2015-11-29 20:27:28 +00:00
|
|
|
int width, height;
|
|
|
|
get_text_size(window, &width, &height, "Test string for measuring purposes");
|
|
|
|
window->height = height + MARGIN * 2;
|
|
|
|
|
2015-11-29 15:58:18 +00:00
|
|
|
do {
|
|
|
|
if (window_prerender(window) && window->cairo) {
|
|
|
|
render();
|
|
|
|
window_render(window);
|
|
|
|
}
|
|
|
|
} while (wl_display_dispatch(registry->display) != -1);
|
|
|
|
|
|
|
|
window_teardown(window);
|
|
|
|
registry_teardown(registry);
|
|
|
|
|
2015-11-29 15:26:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|