suwako / UnixCalc アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

マウスオーバー効果の完了

諏訪子 <suwako@076.moe>、2026-01-22 00:06
コミット e273c38ade6b0debb44784dca5d170230db84d7e ・親 dd3be3a ・ファイルを見る

4個のファイル、+21 -2

変更 control.c
@@ -384,6 +384,14 @@
384384 control_expose(window, labels, &(SuwaButton){0});
385385 }
386386
387+void reset_mouse_hover(SuwaWindow *window, CtrlLabels *labels) {
388+ if (!lasthover) return;
389+ lasthover->hovered = 0;
390+ lasthover = NULL;
391+ window->event = (XEvent){.type = Expose};
392+ control_expose(window, labels, &(SuwaButton){0});
393+}
394+
387395 void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my) {
388396 SuwaButton *btn = find_button_at(window, mx, my);
389397 if (!btn) return;
変更 control.h
@@ -47,4 +47,5 @@
4747 void handle_button_press(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
4848 void handle_button_release(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
4949 void handle_key_press(SuwaWindow *window, CtrlLabels *labels);
50+void reset_mouse_hover(SuwaWindow *window, CtrlLabels *labels);
5051 void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
@@ -334,6 +334,8 @@
334334 | KeyPressMask
335335 | PointerMotionMask
336336 | Button1MotionMask
337+ | EnterWindowMask
338+ | LeaveWindowMask
337339 // | StructureNotifyMask
338340 );
339341
変更 main.c
@@ -113,7 +113,10 @@
113113 case MotionNotify:
114114 Time now = window.event.xmotion.time;
115115 if (now - lasthovertime < 40) break;
116- lasthovertime = now;
116+ if (now - lasthovertime > 80) {
117+ reset_mouse_hover(&window, &lbl);
118+ lasthovertime = now;
119+ }
117120 Window root, child;
118121 int root_x, root_y,
119122 win_x, win_y;
@@ -121,8 +124,13 @@
121124
122125 XQueryPointer(window.display, window.xwindow, &root, &child,
123126 &root_x, &root_y, &win_x, &win_y, &mask);
124- if (window.event.xmotion.state == 0) break;
127+ if (window.event.xmotion.state == 0) {
128+ break;
129+ }
125130 handle_mouse_hover(&window, &lbl, win_x, win_y);
131+ break;
132+ case LeaveNotify:
133+ reset_mouse_hover(&window, &lbl);
126134 break;
127135 case ClientMessage:
128136 // WM_DELETE_WINDOW