From dd3be3a555c5aae19acf95c528046b620fb54363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 21 Jan 2026 23:50:16 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9E=E3=82=A6=E3=82=B9=E3=82=AA=E3=83=BC?= =?UTF-8?q?=E3=83=90=E3=83=BC=E5=8A=B9=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control.c | 24 +++++++----------------- control.h | 2 +- include/suwaui.h | 4 ++-- main.c | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/control.c b/control.c index 54b923f..ecd3503 100644 --- a/control.c +++ b/control.c @@ -54,7 +54,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. char curinput[64] = {0}; int input_pos = 0; int initialized = 0; -SuwaButton buttons[NUM_ROWS][NUM_COLS]; +SuwaButton *lasthover = NULL; static const char *btn_labels[][10] = { { NULL }, // 数字表示 @@ -195,7 +195,6 @@ void initialize_basic_buttons(SuwaWindow *window, XftDraw *backdraw, float scale } } suwaui_draw_button(window, &btn, backdraw); - buttons[row][col] = btn; } } } @@ -385,23 +384,14 @@ redraw: control_expose(window, labels, &(SuwaButton){0}); } -void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels) { - int x = window->event.xmotion.x; - int y = window->event.xmotion.y; - SuwaButton *btn = find_button_at(window, x, y); +void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my) { + SuwaButton *btn = find_button_at(window, mx, my); if (!btn) return; - btn->hovered = 1; - XftDraw *backdraw = XftDrawCreate(window->display, window->backbuf, - DefaultVisual(window->display, DefaultScreen(window->display)), - DefaultColormap(window->display, DefaultScreen(window->display))); - if (!backdraw) { - fprintf(stderr, "Pixmap向けXftDrawの作成に失敗。\n"); - XFreePixmap(window->display, window->backbuf); - window->backbuf = None; - return; - } + if (lasthover && lasthover != btn) lasthover->hovered = 0; + if (btn) btn->hovered = 1; + lasthover = btn; window->event = (XEvent){.type = Expose}; - control_expose(window, labels, btn); + control_expose(window, labels, btn ? btn : &(SuwaButton){0}); } diff --git a/control.h b/control.h index 3fb6546..bf4c904 100644 --- a/control.h +++ b/control.h @@ -47,4 +47,4 @@ void control_expose(SuwaWindow *window, CtrlLabels *labels, SuwaButton *button); void handle_button_press(SuwaWindow *window, CtrlLabels *labels, int mx, int my); void handle_button_release(SuwaWindow *window, CtrlLabels *labels, int mx, int my); void handle_key_press(SuwaWindow *window, CtrlLabels *labels); -void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels); +void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my); diff --git a/include/suwaui.h b/include/suwaui.h index 4d8c2fb..b694580 100644 --- a/include/suwaui.h +++ b/include/suwaui.h @@ -332,8 +332,8 @@ __attribute__((unused)) static SuwaWindow suwaui_create_window(int x, int y, int | ButtonPressMask | ButtonReleaseMask | KeyPressMask - // | PointerMotionMask - // | ButtonMotionMask + | PointerMotionMask + | Button1MotionMask // | StructureNotifyMask ); diff --git a/main.c b/main.c index de9ea24..41bda4a 100644 --- a/main.c +++ b/main.c @@ -43,6 +43,8 @@ const char *sofname = "ucalc"; const char *version = "0.0.0"; const char *disname = "Unix Calc"; +static Time lasthovertime = 0; + int main() { #if defined(__OpenBSD__) SuwaWindow window = suwaui_create_window( @@ -109,7 +111,18 @@ int main() { handle_key_press(&window, &lbl); break; case MotionNotify: - handle_mouse_hover(&window, &lbl); + Time now = window.event.xmotion.time; + if (now - lasthovertime < 40) break; + lasthovertime = now; + Window root, child; + int root_x, root_y, + win_x, win_y; + unsigned int mask; + + XQueryPointer(window.display, window.xwindow, &root, &child, + &root_x, &root_y, &win_x, &win_y, &mask); + if (window.event.xmotion.state == 0) break; + handle_mouse_hover(&window, &lbl, win_x, win_y); break; case ClientMessage: // WM_DELETE_WINDOW