aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2021-05-21 22:41:11 +0200
committerMarvin Borner2021-05-21 22:41:11 +0200
commit93174e167a6aa313fca43f4cb0e9b975e1618468 (patch)
tree6fbed7871cb24f38cc714e6838ac6a6cc0f4fc36 /apps
parent11cdf24db63af9a22786e81e69247f15cc196b0c (diff)
Better window destroying
Diffstat (limited to 'apps')
-rw-r--r--apps/chess/main.c4
-rw-r--r--apps/paint/main.c13
-rw-r--r--apps/wm/main.c12
3 files changed, 18 insertions, 11 deletions
diff --git a/apps/chess/main.c b/apps/chess/main.c
index b0da8d1..8e1d470 100644
--- a/apps/chess/main.c
+++ b/apps/chess/main.c
@@ -214,8 +214,8 @@ static void draw_board(void)
{
for (u8 x = 0; x < 8; x++) {
for (u8 y = 0; y < 8; y++) {
- u32 widget;
- gui_new_widget(&widget, win, vec2(TILE * x, TILE * y), vec2(TILE, TILE));
+ u32 widget = gui_new_widget(win, GUI_MAIN, vec2(TILE * x, TILE * y),
+ vec2(TILE, TILE));
assert((signed)widget > 0);
u8 colored = (x + y + 1) % 2 == 0;
diff --git a/apps/paint/main.c b/apps/paint/main.c
index 50234af..e537004 100644
--- a/apps/paint/main.c
+++ b/apps/paint/main.c
@@ -36,23 +36,20 @@ int main(void)
gui_new_window(&win);
vec2 win_size = gui_window_size(win);
- u32 toolbar;
- gui_new_widget(&toolbar, win, vec2(0, 0), vec2(win_size.x, COLOR_SIZE));
+ u32 toolbar = gui_new_widget(win, GUI_MAIN, vec2(0, 0), vec2(win_size.x, COLOR_SIZE));
gui_fill(win, toolbar, GUI_LAYER_BG, COLOR_WHITE);
u32 color_count = COUNT(colors);
for (u32 i = 0; i < color_count; i++) {
- u32 color;
- gui_add_widget(&color, win, toolbar, vec2(i * (COLOR_SIZE + TOOLBAR_MARGIN), 0),
- vec2(COLOR_SIZE, COLOR_SIZE));
+ u32 color = gui_new_widget(win, toolbar, vec2(i * (COLOR_SIZE + TOOLBAR_MARGIN), 0),
+ vec2(COLOR_SIZE, COLOR_SIZE));
gui_fill(win, color, GUI_LAYER_FG, colors[i]);
gui_draw_border(win, color, GUI_LAYER_FG, 2, COLOR_BLACK);
gui_listen_widget(win, color, GUI_LISTEN_MOUSECLICK, (u32)color_click);
}
- u32 canvas;
- gui_new_widget(&canvas, win, vec2(0, COLOR_SIZE),
- vec2(win_size.x, win_size.y - COLOR_SIZE));
+ u32 canvas = gui_new_widget(win, GUI_MAIN, vec2(0, COLOR_SIZE),
+ vec2(win_size.x, win_size.y - COLOR_SIZE));
gui_fill(win, canvas, GUI_LAYER_BG, COLOR_WHITE);
gui_listen_widget(win, canvas, GUI_LISTEN_MOUSEMOVE, (u32)mousemove);
diff --git a/apps/wm/main.c b/apps/wm/main.c
index a4727ea..698d0cb 100644
--- a/apps/wm/main.c
+++ b/apps/wm/main.c
@@ -364,6 +364,16 @@ static void window_destroy(struct window *win)
free(win);
}
+static void window_request_destroy(struct window *win)
+{
+ struct message_mouse msg = { 0 };
+ msg.header.state = MSG_NEED_ANSWER;
+ msg.id = win->id;
+
+ if (msg_connect_conn(win->client.conn) == EOK)
+ msg_send(GUI_DESTROY_WINDOW, &msg, sizeof(msg));
+}
+
/**
* Window bar
*/
@@ -380,7 +390,7 @@ static void window_bar_mousemove(struct window *win, struct event_mouse *event,
return;
if (pos.x >= win->ctx.size.x - BAR_BUTTONS_WIDTH && event->but.left)
- window_destroy(win);
+ window_request_destroy(win);
else if (event->but.left)
window_move(win, vec2_sub(mouse_pos, vec2(win->ctx.size.x / 2, BAR_HEIGHT / 2)));
}