diff options
Diffstat (limited to 'clients/desktop-shell.c')
-rw-r--r-- | clients/desktop-shell.c | 156 |
1 files changed, 124 insertions, 32 deletions
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index 95b557a..09e8bd6 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -41,18 +41,30 @@ struct desktop { struct display *display; struct desktop_shell *shell; - struct panel *panel; - struct window *background; const char *background_path; struct unlock_dialog *unlock_dialog; struct task unlock_task; }; +struct surface { + void (*configure)(void *data, + struct desktop_shell *desktop_shell, + uint32_t time, uint32_t edges, + struct wl_surface *surface, + int32_t width, int32_t height); +}; + struct panel { + struct surface base; struct window *window; struct window *menu; }; +struct background { + struct surface base; + struct window *window; +}; + struct panel_item { struct item *item; struct panel *panel; @@ -113,6 +125,7 @@ show_menu(struct panel *panel, struct input *input) display = window_get_display(panel->window); panel->menu = window_create_transient(display, panel->window, x - 10, y - 10, width, height); + window_set_user_data(panel->menu, panel); window_draw(panel->menu); window_flush(panel->menu); @@ -234,6 +247,22 @@ panel_button_handler(struct window *window, } } +static void +panel_configure(void *data, + struct desktop_shell *desktop_shell, + uint32_t time, uint32_t edges, + struct wl_surface *surface, + int32_t width, int32_t height) +{ + struct panel *panel = + window_get_user_data(wl_surface_get_user_data(surface)); + + if (surface == window_get_wl_surface(panel->window)) { + window_set_child_size(panel->window, width, 32); + window_schedule_redraw(panel->window); + } +} + static struct panel * panel_create(struct display *display) { @@ -242,8 +271,8 @@ panel_create(struct display *display) panel = malloc(sizeof *panel); memset(panel, 0, sizeof *panel); + panel->base.configure = panel_configure; panel->window = window_create(display, 0, 0); - window_set_title(panel->window, "panel"); window_set_decoration(panel->window, 0); window_set_redraw_handler(panel->window, panel_redraw_handler); @@ -305,6 +334,21 @@ background_draw(struct window *window, int width, int height, const char *path) } static void +background_configure(void *data, + struct desktop_shell *desktop_shell, + uint32_t time, uint32_t edges, + struct wl_surface *surface, + int32_t width, int32_t height) +{ + struct desktop *desktop = data; + struct background *background = + window_get_user_data(wl_surface_get_user_data(surface)); + + background_draw(background->window, + width, height, desktop->background_path); +} + +static void unlock_dialog_draw(struct unlock_dialog *dialog) { struct rectangle allocation; @@ -453,15 +497,13 @@ desktop_shell_configure(void *data, struct wl_surface *surface, int32_t width, int32_t height) { - struct desktop *desktop = data; + struct surface *s = + window_get_user_data(wl_surface_get_user_data(surface)); - if (surface == window_get_wl_surface(desktop->panel->window)) { - window_set_child_size(desktop->panel->window, width, 32); - window_schedule_redraw(desktop->panel->window); - } else if (surface == window_get_wl_surface(desktop->background)) { - background_draw(desktop->background, - width, height, desktop->background_path); - } + if (s == NULL) + return; + + s->configure(data, desktop_shell, time, edges, surface, width, height); } static void @@ -481,6 +523,71 @@ static const struct desktop_shell_listener listener = { desktop_shell_prepare_lock_surface }; +static struct background * +background_create(struct desktop *desktop) +{ + struct background *background; + + background = malloc(sizeof *background); + memset(background, 0, sizeof *background); + + background->base.configure = background_configure; + background->window = window_create(desktop->display, 0, 0); + window_set_decoration(background->window, 0); + window_set_custom(background->window); + window_set_user_data(background->window, background); + + desktop->background_path = key_background_image; + + return background; +} + +static void +output_handle_geometry(void *data, + struct wl_output *wl_output, + int x, int y, + int physical_width, + int physical_height, + int subpixel, + const char *make, + const char *model) +{ + struct desktop *desktop = data; + struct panel *panel; + struct background *background; + char *config_file; + + panel = panel_create(desktop->display); + + config_file = config_file_path("wayland-desktop-shell.ini"); + parse_config_file(config_file, + config_sections, ARRAY_LENGTH(config_sections), + panel); + free(config_file); + + desktop_shell_set_panel(desktop->shell, wl_output, + window_get_wl_surface(panel->window)); + + background = background_create(desktop); + desktop_shell_set_background(desktop->shell, wl_output, + window_get_wl_surface(background->window)); +} + +static void +output_handle_mode(void *data, + struct wl_output *wl_output, + uint32_t flags, + int width, + int height, + int refresh) +{ +} + +static const struct wl_output_listener output_listener = { + output_handle_geometry, + output_handle_mode +}; + static void global_handler(struct wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data) @@ -491,20 +598,24 @@ global_handler(struct wl_display *display, uint32_t id, desktop->shell = wl_display_bind(display, id, &desktop_shell_interface); desktop_shell_add_listener(desktop->shell, &listener, desktop); + } else if (!strcmp(interface, "wl_output")) { + struct wl_output *output = wl_display_bind(display, id, + &wl_output_interface); + wl_output_add_listener(output, &output_listener, desktop); } } static void launcher_section_done(void *data) { - struct desktop *desktop = data; + struct panel *panel = data; if (key_launcher_icon == NULL || key_launcher_path == NULL) { fprintf(stderr, "invalid launcher section\n"); return; } - panel_add_item(desktop->panel, key_launcher_icon, key_launcher_path); + panel_add_item(panel, key_launcher_icon, key_launcher_path); free(key_launcher_icon); key_launcher_icon = NULL; free(key_launcher_path); @@ -514,7 +625,6 @@ launcher_section_done(void *data) int main(int argc, char *argv[]) { struct desktop desktop = { 0 }; - char *config_file; desktop.unlock_task.run = unlock_dialog_finish; @@ -530,24 +640,6 @@ int main(int argc, char *argv[]) wl_display_add_global_listener(display_get_display(desktop.display), global_handler, &desktop); - desktop.panel = panel_create(desktop.display); - - config_file = config_file_path("wayland-desktop-shell.ini"); - parse_config_file(config_file, - config_sections, ARRAY_LENGTH(config_sections), - &desktop); - free(config_file); - - desktop_shell_set_panel(desktop.shell, - window_get_wl_surface(desktop.panel->window)); - - desktop.background = window_create(desktop.display, 0, 0); - window_set_decoration(desktop.background, 0); - window_set_custom(desktop.background); - desktop.background_path = key_background_image; - desktop_shell_set_background(desktop.shell, - window_get_wl_surface(desktop.background)); - signal(SIGCHLD, sigchild_handler); display_run(desktop.display); |