Skip to content

Commit

Permalink
wayland connector update
Browse files Browse the repository at this point in the history
  • Loading branch information
milgra committed Nov 22, 2022
1 parent e58291b commit 2a0a064
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 79 deletions.
94 changes: 48 additions & 46 deletions src/kinetic_ui/ku_connector_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ void ku_wayland_delete_layer();
void ku_wayland_hide_window(struct wl_window* info);
void ku_wayland_show_window(struct wl_window* info);

void ku_wayland_hide_layer(struct wl_window* info);
void ku_wayland_show_layer(struct wl_window* info);

void ku_wayland_exit();
void ku_wayland_toggle_fullscreen();
void ku_wayland_set_time_event_delay(int ms);
Expand Down Expand Up @@ -435,7 +432,7 @@ static const struct wl_callback_listener wl_surface_frame_listener = {

static void ku_wayland_layer_surface_configure(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height)
{
mt_log_debug("layer surface configure serial %u width %i height %i", serial, width, height);
/* mt_log_debug("layer surface configure serial %u width %i height %i", serial, width, height); */

zwlr_layer_surface_v1_ack_configure(surface, serial);

Expand Down Expand Up @@ -815,7 +812,7 @@ void ku_wayland_delete_window(struct wl_window* info)
}
}

void ku_wayland_hide_layer(struct wl_window* info)
void ku_wayland_hide_window(struct wl_window* info)
{
if (info->hidden == 0)
{
Expand All @@ -827,60 +824,66 @@ void ku_wayland_hide_layer(struct wl_window* info)
info->frame_cb = NULL;
}

zwlr_layer_surface_v1_destroy(info->layer_surface);
wl_surface_destroy(info->surface);
if (info->type == WL_WINDOW_LAYER)
{
zwlr_layer_surface_v1_destroy(info->layer_surface);
wl_surface_destroy(info->surface);

info->surface = NULL;
info->layer_surface = NULL;
info->surface = NULL;
info->layer_surface = NULL;
}
}
}

void ku_wayland_show_layer(struct wl_window* info)
void ku_wayland_show_window(struct wl_window* info)
{
if (info->hidden == 1)
{
info->surface = wl_compositor_create_surface(wlc.compositor);

info->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
wlc.layer_shell,
info->surface,
info->monitor->wl_output,
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"wcp");

zwlr_layer_surface_v1_set_size(
info->layer_surface,
info->new_width,
info->new_height);

uint af = 0;
char* anchor = info->anchor;
while (*anchor != '\0')
if (info->type == WL_WINDOW_LAYER)
{
if (*anchor == 'l') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
if (*anchor == 'r') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
if (*anchor == 't') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
if (*anchor == 'b') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
anchor++;
}
info->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
wlc.layer_shell,
info->surface,
info->monitor->wl_output,
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
"wcp");

zwlr_layer_surface_v1_set_size(
info->layer_surface,
info->new_width,
info->new_height);

uint af = 0;
char* anchor = info->anchor;
while (*anchor != '\0')
{
if (*anchor == 'l') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
if (*anchor == 'r') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
if (*anchor == 't') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
if (*anchor == 'b') af |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
anchor++;
}

zwlr_layer_surface_v1_set_anchor(
info->layer_surface,
af);
zwlr_layer_surface_v1_set_anchor(
info->layer_surface,
af);

zwlr_layer_surface_v1_set_margin(
info->layer_surface,
info->margin,
info->margin,
info->margin,
info->margin);
zwlr_layer_surface_v1_set_margin(
info->layer_surface,
info->margin,
info->margin,
info->margin,
info->margin);

zwlr_layer_surface_v1_add_listener(info->layer_surface, &layer_surface_listener, info);
zwlr_layer_surface_v1_add_listener(info->layer_surface, &layer_surface_listener, info);

wl_surface_commit(info->surface);
wl_surface_commit(info->surface);

info->frame_cb = wl_surface_frame(info->surface);
wl_callback_add_listener(info->frame_cb, &wl_surface_frame_listener, info);
info->frame_cb = wl_surface_frame(info->surface);
wl_callback_add_listener(info->frame_cb, &wl_surface_frame_listener, info);
}
}
}

Expand All @@ -900,7 +903,7 @@ struct wl_window* ku_wayland_create_generic_layer(struct monitor_info* monitor,

info->type = WL_WINDOW_LAYER;

ku_wayland_show_layer(info);
ku_wayland_show_window(info);

return info;
}
Expand Down Expand Up @@ -1683,7 +1686,6 @@ void ku_wayland_init(

void ku_wayland_exit()
{
printf("EXIT!!!\n");
wlc.exit_flag = 1;
wl_display_flush(wlc.display);
}
Expand Down
13 changes: 7 additions & 6 deletions src/kinetic_ui/ku_gen_css.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "ku_view.c"
#include "mt_vector.c"

void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* respath, float scale);
void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* imgpath, float scale);

#endif

Expand All @@ -14,7 +14,7 @@ void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* respath, float sc
#include "mt_log.c"
#include <limits.h>

void ku_gen_css_apply_style(ku_view_t* view, mt_map_t* style, char* respath, float scale)
void ku_gen_css_apply_style(ku_view_t* view, mt_map_t* style, char* imgpath, float scale)
{
mt_vector_t* keys = VNEW(); // REL 0
mt_map_keys(style, keys);
Expand All @@ -35,7 +35,8 @@ void ku_gen_css_apply_style(ku_view_t* view, mt_map_t* style, char* respath, flo
{
char* url = CAL(sizeof(char) * strlen(val), NULL, mt_string_describe); // REL 0
memcpy(url, val + 5, strlen(val) - 7);
char* imagepath = mt_string_new_format(100, "%s/img/%s", respath, url);
char* imagepath = mt_string_new_format(100, "%s/%s", imgpath, url);

view->style.background_image = imagepath;
REL(url); // REL 0
}
Expand Down Expand Up @@ -259,7 +260,7 @@ void ku_gen_css_apply_style(ku_view_t* view, mt_map_t* style, char* respath, flo
REL(keys);
}

void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* respath, float scale)
void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* imgpath, float scale)
{
mt_map_t* styles = ku_css_new(csspath);
mt_map_t* style;
Expand All @@ -275,7 +276,7 @@ void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* respath, float sc
style = MGET(styles, cssid);
if (style)
{
ku_gen_css_apply_style(view, style, respath, scale);
ku_gen_css_apply_style(view, style, imgpath, scale);
}

if (view->class)
Expand All @@ -295,7 +296,7 @@ void ku_gen_css_apply(mt_vector_t* views, char* csspath, char* respath, float sc
// mt_log_debug("applying class %s to %s", cls, view->id);
if (style)
{
ku_gen_css_apply_style(view, style, respath, scale);
ku_gen_css_apply_style(view, style, imgpath, scale);
}
} while ((token = strtok(NULL, " ")));
}
Expand Down
38 changes: 17 additions & 21 deletions src/wcp/ui.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef ui_h
#define ui_h

#include "ku_connector_wayland.c"
#include "ku_window.c"

void ui_init(int width, int height, float scale, ku_window_t* window);
void ui_init(int width, int height, float scale, ku_window_t* window, struct wl_window* wlwindow);
void ui_destroy();
void ui_load_values();

Expand All @@ -13,7 +14,6 @@ void ui_load_values();

#include "config.c"
#include "ku_bitmap.c"
#include "ku_connector_wayland.c"
#include "ku_draw.c"
#include "ku_gen_css.c"
#include "ku_gen_html.c"
Expand Down Expand Up @@ -41,13 +41,14 @@ void ui_load_values();

struct _ui_t
{
ku_view_t* view_base;
mt_vector_t* view_list;
char* command;
pthread_t thread;
ku_window_t* window;
pthread_cond_t comm_cond;
pthread_mutex_t comm_mutex;
struct wl_window* wlwindow;
ku_view_t* view_base;
mt_vector_t* view_list;
char* command;
pthread_t thread;
ku_window_t* window;
pthread_cond_t comm_cond;
pthread_mutex_t comm_mutex;
} ui;

int ui_execute_command(char* command, char** result)
Expand Down Expand Up @@ -102,14 +103,12 @@ void ui_on_button_event(vh_button_event_t event)
{
if (!ui.command)
{
char* script = mt_path_new_append(config_get("res_path"), "script/");
char* command = mt_string_new_format(200, "sh %s%s 1", script, event.view->script);
char* command = mt_string_new_format(200, "sh %s/%s 1", config_get("scr_path"), event.view->script);
ui.command = command;
REL(script);
pthread_cond_signal(&ui.comm_cond);
}

/* ku_wayland_hide_window(ui.window); */
ku_wayland_hide_window(ui.wlwindow);
}

void ui_on_slider_event(vh_slider_event_t event)
Expand All @@ -118,10 +117,8 @@ void ui_on_slider_event(vh_slider_event_t event)

if (!ui.command)
{
char* script = mt_path_new_append(config_get("res_path"), "script/");
char* command = mt_string_new_format(200, "sh %s%s %i", script, event.view->script, ratio);
char* command = mt_string_new_format(200, "sh %s/%s %i", config_get("scr_path"), event.view->script, ratio);
ui.command = command;
REL(script);
pthread_cond_signal(&ui.comm_cond);
}
}
Expand All @@ -134,8 +131,7 @@ void ui_load_values()

if (view->script)
{
char* script = mt_path_new_append(config_get("res_path"), "script/");
char* command = mt_string_new_format(200, "sh %s%s", script, view->script);
char* command = mt_string_new_format(200, "sh %s/%s", config_get("scr_path"), view->script);
char* result = mt_string_new_cstring("");
ui_execute_command(command, &result);

Expand All @@ -148,18 +144,18 @@ void ui_load_values()
float ratio = (float) atoi(result) / 100.0;
vh_slider_set(view, ratio);
}
REL(script);
REL(result);
REL(command);
}
}
}

void ui_init(int width, int height, float scale, ku_window_t* window)
void ui_init(int width, int height, float scale, ku_window_t* window, struct wl_window* wlwindow)
{
ku_text_init();

ui.window = window;
ui.wlwindow = wlwindow;
ui.view_list = VNEW();

pthread_cond_init(&ui.comm_cond, NULL);
Expand All @@ -170,7 +166,7 @@ void ui_init(int width, int height, float scale, ku_window_t* window)
/* generate views from descriptors */

ku_gen_html_parse(config_get("html_path"), ui.view_list);
ku_gen_css_apply(ui.view_list, config_get("css_path"), config_get("res_path"), 1.0);
ku_gen_css_apply(ui.view_list, config_get("css_path"), config_get("img_path"), 1.0);
ku_gen_type_apply(ui.view_list, ui_on_button_event, ui_on_slider_event);

ui.view_base = mt_vector_head(ui.view_list);
Expand Down
15 changes: 9 additions & 6 deletions src/wcp/wcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void init(wl_event_t event)
wcp.wlwindow = ku_wayland_create_generic_layer(monitor, wcp.width, wcp.height, wcp.margin, wcp.anchor);
wcp.kuwindow = ku_window_create(wcp.width, wcp.height);

ui_init(monitor->logical_width, monitor->logical_height, monitor->scale, wcp.kuwindow);
ui_init(monitor->logical_width, monitor->logical_height, monitor->scale, wcp.kuwindow, wcp.wlwindow);
}

/* window update */
Expand All @@ -45,24 +45,23 @@ void update(ku_event_t ev)
{
if (ev.type == KU_EVENT_STDIN)
{
if (ev.text[0] == '0' && wcp.wlwindow->hidden == 0) ku_wayland_hide_layer(wcp.wlwindow);
if (ev.text[0] == '0' && wcp.wlwindow->hidden == 0) ku_wayland_hide_window(wcp.wlwindow);
if (ev.text[0] == '1' && wcp.wlwindow->hidden == 1)
{
ku_wayland_show_layer(wcp.wlwindow);
ku_wayland_show_window(wcp.wlwindow);
ui_load_values();
}
if (ev.text[0] == '2')
{
if (wcp.wlwindow->hidden == 0) ku_wayland_hide_layer(wcp.wlwindow);
if (wcp.wlwindow->hidden == 0) ku_wayland_hide_window(wcp.wlwindow);
else if (wcp.wlwindow->hidden == 1)
{
ku_wayland_show_layer(wcp.wlwindow);
ku_wayland_show_window(wcp.wlwindow);
ui_load_values();
}
}
if (ev.text[0] == '3') ku_wayland_exit();
}
if (ev.type == KU_EVENT_MUP) ku_wayland_hide_layer(wcp.wlwindow);

ku_window_event(wcp.kuwindow, ev);

Expand Down Expand Up @@ -180,6 +179,7 @@ int main(int argc, char* argv[])

char* css_path = mt_path_new_append(res_path, "html/main.css"); // REL 6
char* html_path = mt_path_new_append(res_path, "html/main.html"); // REL 7
char* img_path = mt_path_new_append(res_path, "img"); // REL 6
char* scr_path = mt_path_new_append(res_path, "script"); // REL 8

// print path info to console
Expand All @@ -188,6 +188,7 @@ int main(int argc, char* argv[])
printf("resource path : %s\n", res_path);
printf("css path : %s\n", css_path);
printf("html path : %s\n", html_path);
printf("image path : %s\n", img_path);
printf("script path : %s\n", scr_path);
printf("\n");

Expand All @@ -204,6 +205,7 @@ int main(int argc, char* argv[])
config_set("css_path", css_path);
config_set("html_path", html_path);
config_set("scr_path", scr_path);
config_set("img_path", img_path);

wcp.width = 300;
wcp.height = 300;
Expand Down Expand Up @@ -242,6 +244,7 @@ int main(int argc, char* argv[])
REL(css_path); // REL 6
REL(html_path); // REL 7
REL(scr_path); // REL 8
REL(img_path);

#ifdef MT_MEMORY_DEBUG
mt_memory_stats();
Expand Down

0 comments on commit 2a0a064

Please sign in to comment.