diff --git a/cleonos/c/apps/file_explorer_main.c b/cleonos/c/apps/file_explorer_main.c index 2709065..57a8ee6 100644 --- a/cleonos/c/apps/file_explorer_main.c +++ b/cleonos/c/apps/file_explorer_main.c @@ -20,7 +20,8 @@ typedef unsigned int fx_u32; #define FX_ROW_H 24 #define FX_HEADER_H 24 #define FX_PREVIEW_H 104 -#define FX_CLOSE_W 44 +#define FX_CONTROL_W 46 +#define FX_CLOSE_W FX_CONTROL_W #define FX_MIN_W 420 #define FX_MIN_H 360 #define FX_DEFAULT_W 760 @@ -44,6 +45,8 @@ typedef unsigned int fx_u32; #define FX_COLOR_SELECT 0x00CDE8FFU #define FX_COLOR_BUTTON 0x00E7E7E7U #define FX_COLOR_BUTTON_HOT 0x00D8EBFAU +#define FX_COLOR_CONTROL_INACTIVE 0x00E5E5E5U +#define FX_COLOR_CONTROL_ACTIVE 0x001A5EA0U #define FX_GLYPH7(r0, r1, r2, r3, r4, r5, r6) \ (((u64)(r0) << 30U) | ((u64)(r1) << 25U) | ((u64)(r2) << 20U) | ((u64)(r3) << 15U) | ((u64)(r4) << 10U) | \ @@ -67,6 +70,7 @@ typedef struct fx_app { fx_u32 *pixels; u64 pixel_count; int running; + int focused; int dragging; int drag_dx; int drag_dy; @@ -638,6 +642,27 @@ static void fx_draw_button(fx_app *app, int x, int y, int w, int h, const char * fx_draw_text_limit(app, x + 10, y + ((h - 7) / 2), label, 1, FX_COLOR_TEXT, x + w - 8); } +static void fx_draw_control_button(fx_app *app, int x, int active, int kind) { + fx_u32 bg = (kind == 2) ? FX_COLOR_CLOSE : (active != 0 ? FX_COLOR_CONTROL_ACTIVE : FX_COLOR_CONTROL_INACTIVE); + fx_u32 fg = (kind == 2 || active != 0) ? FX_COLOR_WHITE : FX_COLOR_TEXT; + int cy = FX_TITLE_H / 2; + int cx = x + (FX_CONTROL_W / 2); + + fx_fill_rect(app, x, 0, FX_CONTROL_W, FX_TITLE_H, bg); + if (kind == 0) { + fx_fill_rect(app, cx - 6, cy + 4, 12, 1, fg); + } else if (kind == 1) { + fx_stroke_rect(app, cx - 6, cy - 6, 12, 12, fg); + fx_fill_rect(app, cx - 6, cy - 6, 12, 2, fg); + } else { + int i; + for (i = 0; i < 11; i++) { + fx_fill_rect(app, cx - 5 + i, cy - 5 + i, 1, 1, fg); + fx_fill_rect(app, cx + 5 - i, cy - 5 + i, 1, 1, fg); + } + } +} + static void fx_draw_preview(fx_app *app, int y, int h) { int line = 0; int cursor_y; @@ -701,15 +726,21 @@ static void fx_render(fx_app *app) { int list_bottom = preview_y; int rows; int i; + fx_u32 title_bg; + fx_u32 title_fg; const char *quick_names[] = {"ROOT", "SYSTEM", "SHELL", "UWM", "TEMP", "DRIVER", "DEV"}; const char *quick_paths[] = {"/", "/system", "/shell", "/shell/uwm", "/temp", "/driver", "/dev"}; + title_bg = (app->focused != 0) ? FX_COLOR_WIN_BLUE : FX_COLOR_TITLE_INACTIVE; + title_fg = (app->focused != 0) ? FX_COLOR_WHITE : FX_COLOR_TEXT; fx_fill_rect(app, 0, 0, app->w, app->h, FX_COLOR_BG); - fx_fill_rect(app, 0, 0, app->w, FX_TITLE_H, FX_COLOR_WIN_BLUE); - fx_draw_text(app, 12, 12, "FILE EXPLORER", 1, FX_COLOR_WHITE); - fx_fill_rect(app, app->w - FX_CLOSE_W, 0, FX_CLOSE_W, FX_TITLE_H, FX_COLOR_CLOSE); - fx_fill_rect(app, app->w - 28, 14, 14, 2, FX_COLOR_WHITE); - fx_fill_rect(app, app->w - 22, 9, 2, 12, FX_COLOR_WHITE); + fx_fill_rect(app, 0, 0, app->w, FX_TITLE_H, title_bg); + fx_fill_rect(app, 0, FX_TITLE_H, app->w, 1, FX_COLOR_BORDER); + fx_stroke_rect(app, 0, 0, app->w, app->h, FX_COLOR_BORDER); + fx_draw_text_limit(app, 12, 12, "FILE EXPLORER", 1, title_fg, app->w - (FX_CONTROL_W * 3) - 8); + fx_draw_control_button(app, app->w - (FX_CONTROL_W * 3), app->focused, 0); + fx_draw_control_button(app, app->w - (FX_CONTROL_W * 2), app->focused, 1); + fx_draw_control_button(app, app->w - FX_CONTROL_W, app->focused, 2); fx_fill_rect(app, 0, FX_TITLE_H, app->w, FX_TOOLBAR_H, FX_COLOR_PANEL); fx_fill_rect(app, 0, FX_TITLE_H + FX_TOOLBAR_H - 1, app->w, 1, FX_COLOR_BORDER); @@ -904,10 +935,13 @@ static void fx_handle_mouse_button(fx_app *app, const cleonos_wm_event *event) { return; } if (local_y >= 0 && local_y < FX_TITLE_H) { - if (local_x >= app->w - FX_CLOSE_W) { + if (local_x >= app->w - FX_CONTROL_W) { app->running = 0; return; } + if (local_x >= app->w - (FX_CONTROL_W * 3)) { + return; + } app->dragging = 1; app->drag_dx = local_x; app->drag_dy = local_y; @@ -979,7 +1013,12 @@ static void fx_loop(fx_app *app) { } handled = 1; dirty = 1; - if (event.type == CLEONOS_WM_EVENT_KEY) { + if (event.type == CLEONOS_WM_EVENT_FOCUS_GAINED) { + app->focused = 1; + } else if (event.type == CLEONOS_WM_EVENT_FOCUS_LOST) { + app->focused = 0; + app->dragging = 0; + } else if (event.type == CLEONOS_WM_EVENT_KEY) { fx_handle_key(app, event.arg0); } else if (event.type == CLEONOS_WM_EVENT_MOUSE_BUTTON) { fx_handle_mouse_button(app, &event); @@ -1065,6 +1104,7 @@ static int fx_init_window(fx_app *app) { return 0; } (void)cleonos_sys_wm_set_focus(app->window_id); + app->focused = 1; return 1; } diff --git a/cleonos/c/apps/taskmgr_main.c b/cleonos/c/apps/taskmgr_main.c index 493dffd..e154d36 100644 --- a/cleonos/c/apps/taskmgr_main.c +++ b/cleonos/c/apps/taskmgr_main.c @@ -15,7 +15,8 @@ typedef unsigned int tm_u32; #define TM_HEADER_H 26 #define TM_STATUS_H 28 #define TM_ROW_H 24 -#define TM_CLOSE_W 46 +#define TM_CONTROL_W 46 +#define TM_CLOSE_W TM_CONTROL_W #define TM_MAX_ROWS 96U #define TM_EVENT_BUDGET 96ULL #define TM_REFRESH_TICKS 45ULL @@ -30,6 +31,7 @@ typedef unsigned int tm_u32; #define TM_COLOR_PANEL 0x00FFFFFFU #define TM_COLOR_TITLE 0x000078D7U #define TM_COLOR_CLOSE 0x00E81123U +#define TM_COLOR_TITLE_INACTIVE 0x00F3F3F3U #define TM_COLOR_TEXT 0x00232323U #define TM_COLOR_MUTED 0x00666666U #define TM_COLOR_BORDER 0x00D0D0D0U @@ -38,6 +40,8 @@ typedef unsigned int tm_u32; #define TM_COLOR_SELECT_BORDER 0x0078BDE8U #define TM_COLOR_BUTTON 0x00E7E7E7U #define TM_COLOR_BUTTON_HOT 0x00D8EBFAU +#define TM_COLOR_CONTROL_INACTIVE 0x00E5E5E5U +#define TM_COLOR_CONTROL_ACTIVE 0x001A5EA0U #define TM_COLOR_WARN 0x00FFF4CEU #define TM_COLOR_BAD 0x00FDE7E9U #define TM_COLOR_GOOD 0x00DFF6DDU @@ -57,6 +61,7 @@ typedef struct tm_app { u64 old_tty; int tty_switched; int running; + int focused; int dragging; int drag_dx; int drag_dy; @@ -408,6 +413,27 @@ static void tm_draw_button(int canvas_w, int canvas_h, int x, int y, int w, int tm_draw_text_limit(canvas_w, canvas_h, x + 10, y + ((h - 7) / 2), label, 1, TM_COLOR_TEXT, x + w - 6); } +static void tm_draw_control_button(int canvas_w, int canvas_h, int x, int active, int kind) { + tm_u32 bg = (kind == 2) ? TM_COLOR_CLOSE : (active != 0 ? TM_COLOR_CONTROL_ACTIVE : TM_COLOR_CONTROL_INACTIVE); + tm_u32 fg = (kind == 2 || active != 0) ? TM_COLOR_WHITE : TM_COLOR_TEXT; + int cy = TM_TITLE_H / 2; + int cx = x + (TM_CONTROL_W / 2); + + tm_fill_rect(canvas_w, canvas_h, x, 0, TM_CONTROL_W, TM_TITLE_H, bg); + if (kind == 0) { + tm_fill_rect(canvas_w, canvas_h, cx - 6, cy + 4, 12, 1, fg); + } else if (kind == 1) { + tm_stroke_rect(canvas_w, canvas_h, cx - 6, cy - 6, 12, 12, fg); + tm_fill_rect(canvas_w, canvas_h, cx - 6, cy - 6, 12, 2, fg); + } else { + int i; + for (i = 0; i < 11; i++) { + tm_fill_rect(canvas_w, canvas_h, cx - 5 + i, cy - 5 + i, 1, 1, fg); + tm_fill_rect(canvas_w, canvas_h, cx + 5 - i, cy - 5 + i, 1, 1, fg); + } + } +} + static int tm_visible_rows(const tm_app *app) { int list_top; int list_bottom; @@ -552,17 +578,22 @@ static int tm_present(const tm_app *app) { } static void tm_draw_titlebar(const tm_app *app) { - int close_x; + tm_u32 title_bg; + tm_u32 title_fg; if (app == (const tm_app *)0) { return; } - close_x = app->w - TM_CLOSE_W; - tm_fill_rect(app->w, app->h, 0, 0, app->w, TM_TITLE_H, TM_COLOR_TITLE); - tm_draw_text(app->w, app->h, 14, 12, "TASK MANAGER", 1, TM_COLOR_WHITE); - tm_fill_rect(app->w, app->h, close_x, 0, TM_CLOSE_W, TM_TITLE_H, TM_COLOR_CLOSE); - tm_draw_text(app->w, app->h, close_x + 18, 12, "X", 1, TM_COLOR_WHITE); + title_bg = (app->focused != 0) ? TM_COLOR_TITLE : TM_COLOR_TITLE_INACTIVE; + title_fg = (app->focused != 0) ? TM_COLOR_WHITE : TM_COLOR_TEXT; + tm_fill_rect(app->w, app->h, 0, 0, app->w, TM_TITLE_H, title_bg); + tm_fill_rect(app->w, app->h, 0, TM_TITLE_H, app->w, 1, TM_COLOR_BORDER); + tm_stroke_rect(app->w, app->h, 0, 0, app->w, app->h, TM_COLOR_BORDER); + tm_draw_text_limit(app->w, app->h, 14, 12, "TASK MANAGER", 1, title_fg, app->w - (TM_CONTROL_W * 3) - 8); + tm_draw_control_button(app->w, app->h, app->w - (TM_CONTROL_W * 3), app->focused, 0); + tm_draw_control_button(app->w, app->h, app->w - (TM_CONTROL_W * 2), app->focused, 1); + tm_draw_control_button(app->w, app->h, app->w - TM_CONTROL_W, app->focused, 2); } static void tm_draw_toolbar(const tm_app *app) { @@ -792,7 +823,7 @@ static int tm_hit_close(const tm_app *app, int local_x, int local_y) { if (app == (const tm_app *)0) { return 0; } - return (local_x >= app->w - TM_CLOSE_W && local_x < app->w && local_y >= 0 && local_y < TM_TITLE_H) ? 1 : 0; + return (local_x >= app->w - TM_CONTROL_W && local_x < app->w && local_y >= 0 && local_y < TM_TITLE_H) ? 1 : 0; } static int tm_hit_rect(int local_x, int local_y, int x, int y, int w, int h) { @@ -898,6 +929,19 @@ static void tm_handle_event(tm_app *app, const cleonos_wm_event *event) { return; } + if (event->type == CLEONOS_WM_EVENT_FOCUS_GAINED) { + app->focused = 1; + tm_render(app); + return; + } + + if (event->type == CLEONOS_WM_EVENT_FOCUS_LOST) { + app->focused = 0; + app->dragging = 0; + tm_render(app); + return; + } + if (event->type == CLEONOS_WM_EVENT_KEY) { tm_handle_key(app, event->arg0); return; @@ -923,6 +967,9 @@ static void tm_handle_event(tm_app *app, const cleonos_wm_event *event) { return; } if (local_y >= 0 && local_y < TM_TITLE_H) { + if (local_x >= app->w - (TM_CONTROL_W * 3)) { + return; + } app->dragging = 1; app->drag_dx = local_x; app->drag_dy = local_y; @@ -1039,6 +1086,9 @@ static int tm_create_window(tm_app *app) { req.height = (u64)(unsigned int)app->h; req.flags = 0ULL; app->window_id = cleonos_sys_wm_create(&req); + if (app->window_id != 0ULL) { + app->focused = 1; + } return (app->window_id != 0ULL) ? 1 : 0; } diff --git a/cleonos/c/apps/terminal/terminal.c b/cleonos/c/apps/terminal/terminal.c index 5a8371c..10e7d14 100644 --- a/cleonos/c/apps/terminal/terminal.c +++ b/cleonos/c/apps/terminal/terminal.c @@ -26,6 +26,8 @@ #define TERM_COLOR_TEXT 0x00232323U #define TERM_COLOR_MUTED 0x00666666U #define TERM_COLOR_BORDER 0x00D0D0D0U +#define TERM_COLOR_CONTROL_INACTIVE 0x00E5E5E5U +#define TERM_COLOR_CONTROL_ACTIVE 0x001A5EA0U #define TERM_COLOR_BG 0x000C0C0CU #define TERM_COLOR_BAR 0x00111111U #define TERM_COLOR_DEFAULT 0x00DCDCDCU @@ -331,7 +333,7 @@ static void term_draw_text(term_app *app, int x, int y, const char *text, int sc } static void term_draw_control_button(term_app *app, int x, int active, int kind) { - term_u32 bg = (kind == 2) ? TERM_COLOR_CLOSE : (active != 0 ? 0x001A5EA0U : 0x00E5E5E5U); + term_u32 bg = (kind == 2) ? TERM_COLOR_CLOSE : (active != 0 ? TERM_COLOR_CONTROL_ACTIVE : TERM_COLOR_CONTROL_INACTIVE); term_u32 fg = (kind == 2 || active != 0) ? TERM_COLOR_WHITE : TERM_COLOR_TEXT; int cy = TERM_TITLE_H / 2; int cx = x + (TERM_CONTROL_W / 2); @@ -651,6 +653,7 @@ static void term_render(term_app *app) { term_fill_rect(app, 0, 0, app->w, app->h, TERM_COLOR_BG); term_fill_rect(app, 0, 0, app->w, TERM_TITLE_H, title_bg); term_fill_rect(app, 0, TERM_TITLE_H, app->w, 1, TERM_COLOR_BORDER); + term_stroke_rect(app, 0, 0, app->w, app->h, TERM_COLOR_BORDER); term_draw_text_limit(app, 12, 12, "TERMINAL", 1, title_fg, app->w - (TERM_CONTROL_W * 3) - 8); term_draw_control_button(app, app->w - (TERM_CONTROL_W * 3), app->focused, 0); term_draw_control_button(app, app->w - (TERM_CONTROL_W * 2), app->focused, app->maximized != 0 ? 3 : 1);