compositor: Add I-beam cursor; logic in terminal, file-browser

This commit is contained in:
K. Lange 2021-09-16 16:55:43 +09:00
parent 1854b01887
commit 4901a7e538
8 changed files with 43 additions and 13 deletions

View File

@ -530,6 +530,7 @@ static void draw_cursor(yutani_globals_t * yg, int x, int y, int cursor) {
case YUTANI_CURSOR_TYPE_RESIZE_UP_DOWN: sprite = &yg->mouse_sprite_resize_da; break;
case YUTANI_CURSOR_TYPE_RESIZE_DOWN_UP: sprite = &yg->mouse_sprite_resize_db; break;
case YUTANI_CURSOR_TYPE_POINT: sprite = &yg->mouse_sprite_point; break;
case YUTANI_CURSOR_TYPE_IBEAM: sprite = &yg->mouse_sprite_ibeam; break;
}
}
if (sprite != previous) {
@ -2091,6 +2092,7 @@ int main(int argc, char * argv[]) {
load_sprite(&yg->mouse_sprite_resize_da, MOUSE_DIR "resize-uldr.png");
load_sprite(&yg->mouse_sprite_resize_db, MOUSE_DIR "resize-dlur.png");
load_sprite(&yg->mouse_sprite_point, MOUSE_DIR "point.png");
load_sprite(&yg->mouse_sprite_ibeam, MOUSE_DIR "ibeam.png");
TRACE("Done.");
TRACE("Initializing variables...");

View File

@ -2221,6 +2221,9 @@ int main(int argc, char * argv[]) {
}
}
}
if (main_window->mouse_state == YUTANI_CURSOR_TYPE_IBEAM) {
yutani_window_show_mouse(yctx, main_window, YUTANI_CURSOR_TYPE_RESET);
}
} else {
_set_hilight(-1,0);
if (me->command == YUTANI_MOUSE_EVENT_DOWN) {
@ -2228,9 +2231,15 @@ int main(int argc, char * argv[]) {
_figure_out_navbar_cursor(me->new_x, bounds);
redraw = 1;
}
if (main_window->mouse_state == YUTANI_CURSOR_TYPE_RESET) {
yutani_window_show_mouse(yctx, main_window, YUTANI_CURSOR_TYPE_IBEAM);
}
}
}
} else {
if (main_window->mouse_state == YUTANI_CURSOR_TYPE_IBEAM) {
yutani_window_show_mouse(yctx, main_window, YUTANI_CURSOR_TYPE_RESET);
}
if (me->command == YUTANI_MOUSE_EVENT_DOWN) {
if (nav_bar_focused) {
nav_bar_focused = 0;

View File

@ -1983,16 +1983,27 @@ static void * handle_incoming(void) {
menu_bar_mouse_event(yctx, window, &terminal_menu_bar, me, me->new_x, me->new_y);
}
if (me->new_x < 0 || me->new_y < 0) break;
if (!_no_frame) {
if (me->new_x >= (int)window_width + (int)decor_width) break;
if (me->new_y < (int)decor_top_height+menu_bar_height) break;
if (me->new_y >= (int)(window_height + decor_top_height+menu_bar_height)) break;
if (me->new_x < (int)decor_left_width) break;
if (me->new_x >= (int)(window_width + decor_left_width)) break;
if (me->new_x < 0 || me->new_y < 0 ||
(!_no_frame && (me->new_x >= (int)window_width + (int)decor_width ||
me->new_y < (int)decor_top_height+menu_bar_height ||
me->new_y >= (int)(window_height + decor_top_height+menu_bar_height) ||
me->new_x < (int)decor_left_width ||
me->new_x >= (int)(window_width + decor_left_width))) ||
(me->new_x >= (int)window_width || me->new_y >= (int)window_height)) {
if (window->mouse_state == YUTANI_CURSOR_TYPE_IBEAM) {
yutani_window_show_mouse(yctx, window, YUTANI_CURSOR_TYPE_RESET);
}
break;
}
if (!(ansi_state->mouse_on & TERMEMU_MOUSE_ENABLE)) {
if (window->mouse_state == YUTANI_CURSOR_TYPE_RESET) {
yutani_window_show_mouse(yctx, window, YUTANI_CURSOR_TYPE_IBEAM);
}
} else {
if (me->new_x >= (int)window_width) break;
if (me->new_y >= (int)window_height) break;
if (window->mouse_state == YUTANI_CURSOR_TYPE_IBEAM) {
yutani_window_show_mouse(yctx, window, YUTANI_CURSOR_TYPE_RESET);
}
}
int new_x = me->new_x;

View File

@ -216,6 +216,7 @@ typedef struct YutaniGlobals {
sprite_t mouse_sprite_resize_da;
sprite_t mouse_sprite_resize_db;
sprite_t mouse_sprite_point;
sprite_t mouse_sprite_ibeam;
int current_cursor;
/* Server backend communication identifier */

View File

@ -79,6 +79,8 @@ typedef struct yutani_window {
/* Server context that owns this window */
yutani_t * ctx;
int32_t mouse_state;
} yutani_window_t;
typedef struct yutani_message {
@ -458,6 +460,7 @@ struct yutani_msg_clipboard {
#define YUTANI_CURSOR_TYPE_RESIZE_UP_DOWN 5
#define YUTANI_CURSOR_TYPE_RESIZE_DOWN_UP 6
#define YUTANI_CURSOR_TYPE_POINT 7
#define YUTANI_CURSOR_TYPE_IBEAM 8
/*
* YUTANI_WINDOW_FLAG

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

View File

@ -328,7 +328,7 @@ int decor_handle_event(yutani_t * yctx, yutani_msg_t * m) {
} else {
if (old_resize_direction != SCALE_NONE) {
yutani_window_show_mouse(yctx, window, YUTANI_CURSOR_TYPE_RESET);
old_resize_direction = 0;
old_resize_direction = SCALE_NONE;
}
}
}

View File

@ -585,6 +585,7 @@ yutani_window_t * yutani_window_create_flags(yutani_t * y, int width, int height
win->y = 0;
win->user_data = NULL;
win->ctx = y;
win->mouse_state = -1;
free(mm);
hashmap_set(y->windows, (void*)(uintptr_t)win->wid, win);
@ -979,9 +980,12 @@ void yutani_window_warp_mouse(yutani_t * yctx, yutani_window_t * window, int32_t
* TODO: We should add a way to use client-provided cursor textures.
*/
void yutani_window_show_mouse(yutani_t * yctx, yutani_window_t * window, int32_t show_mouse) {
yutani_msg_buildx_window_show_mouse_alloc(m);
yutani_msg_buildx_window_show_mouse(m, window->wid, show_mouse);
yutani_msg_send(yctx, m);
if (window->mouse_state != show_mouse) {
window->mouse_state = show_mouse;
yutani_msg_buildx_window_show_mouse_alloc(m);
yutani_msg_buildx_window_show_mouse(m, window->wid, show_mouse);
yutani_msg_send(yctx, m);
}
}
/**