@@ -119,40 +119,43 @@ static int post_mouse_button_event(uiohook_event * const event) {
119119static int post_mouse_wheel_event (uiohook_event * const event ) {
120120 int status = UIOHOOK_FAILURE ;
121121
122- XButtonEvent btn_event = {
123- .serial = 0 ,
124- .send_event = False ,
125- .display = helper_disp ,
122+ if (uio_event .data .wheel .delta > 0 ) {
123+ XButtonEvent btn_event = {
124+ .serial = 0 ,
125+ .send_event = False ,
126+ .display = helper_disp ,
126127
127- .window = None , /* “event” window it is reported relative to */
128- .root = None , /* root window that the event occurred on */
129- .subwindow = XDefaultRootWindow (helper_disp ), /* child window */
128+ .window = None , /* “event” window it is reported relative to */
129+ .root = None , /* root window that the event occurred on */
130+ .subwindow = XDefaultRootWindow (helper_disp ), /* child window */
130131
131- .time = CurrentTime ,
132+ .time = CurrentTime ,
132133
133- .x = event -> data .wheel .x , /* pointer x, y coordinates in event window */
134- .y = event -> data .wheel .y ,
134+ .x = event -> data .wheel .x , /* pointer x, y coordinates in event window */
135+ .y = event -> data .wheel .y ,
135136
136- .x_root = 0 , /* coordinates relative to root */
137- .y_root = 0 ,
137+ .x_root = 0 , /* coordinates relative to root */
138+ .y_root = 0 ,
138139
139- .state = 0x00 , /* key or button mask */
140- .same_screen = True
141- };
140+ .state = 0x00 , /* key or button mask */
141+ .same_screen = True
142+ };
142143
143- // Wheel events should be the same as click events on X11.
144- // type, amount and rotation
145- unsigned int button = button_map_lookup (event -> data .wheel .rotation < 0 ? WheelUp : WheelDown );
144+ unsigned int button = button_map_lookup (event -> data .wheel .rotation < 0 ? WheelUp : WheelDown );
146145
147- if (XTestFakeButtonEvent (helper_disp , button , True , 0 ) != 0 ) {
146+ // X11 does not support a rotation amount so we will emulate the number of rotations based on the static wheel amount.
147+ // TODO What are we going to do about type=WHEEL_BLOCK_SCROLL?
148+ // TODO What are we going to do about amount=? Is this really a setting, not event property?
148149 status = UIOHOOK_SUCCESS ;
150+ for (int i = abs (event -> data .wheel .rotation ) / (event .data .wheel .delta * event .data .wheel .amount ); i > 0 && status == UIOHOOK_SUCCESS ; i -- ) {
151+ // Wheel events are be the same as click events on X11.
152+ if (!XTestFakeButtonEvent (helper_disp , button , True , 0 ) || !XTestFakeButtonEvent (helper_disp , button , False , 0 )) {
153+ status = UIOHOOK_FAILURE ;
154+ }
155+ }
149156 }
150157
151- if (status == UIOHOOK_SUCCESS && XTestFakeButtonEvent (helper_disp , button , False , 0 ) == 0 ) {
152- status = UIOHOOK_FAILURE ;
153- }
154-
155- return UIOHOOK_SUCCESS ;
158+ return status ;
156159}
157160
158161static int post_mouse_motion_event (uiohook_event * const event ) {
0 commit comments