@@ -240,8 +240,12 @@ void switch_virtual_desktop(device_t *state, output_t *output, int new_index, in
240240void do_screen_switch (device_t * state , int direction ) {
241241 output_t * output = & state -> config .output [state -> active_output ];
242242
243- /* No switching allowed if explicitly disabled or in gaming mode */
244- if (state -> switch_lock || state -> gaming_mode )
243+ /* No switching allowed if explicitly disabled */
244+ if (state -> switch_lock )
245+ return ;
246+
247+ /* In gaming mode, only allow switching if edge detection enabled and triggered */
248+ if (state -> gaming_mode && !state -> config .gaming_edge_enabled )
245249 return ;
246250
247251 /* We want to jump in the direction of the other computer */
@@ -317,6 +321,47 @@ mouse_report_t create_mouse_report(device_t *state, mouse_values_t *values) {
317321 return mouse_report ;
318322}
319323
324+ enum screen_pos_e check_gaming_edge_switch (device_t * state , int offset_x ) {
325+ // Feature disabled - return early
326+ if (!state -> config .gaming_edge_enabled || !state -> gaming_mode )
327+ return NONE ;
328+
329+ output_t * output = & state -> config .output [state -> active_output ];
330+ uint64_t now = time_us_64 ();
331+ uint64_t window_us = state -> config .gaming_edge_window_ms * 1000 ;
332+
333+ // Determine which direction would switch screens
334+ enum screen_pos_e switch_direction = (output -> pos == LEFT ) ? RIGHT : LEFT ;
335+
336+ // Check if movement is toward the other PC
337+ bool moving_toward_switch = (switch_direction == LEFT && offset_x < 0 ) ||
338+ (switch_direction == RIGHT && offset_x > 0 );
339+
340+ // Reset accumulator if:
341+ // - Time window expired
342+ // - Moving in opposite direction
343+ if ((now - state -> gaming_edge_last_reset ) > window_us || !moving_toward_switch ) {
344+ state -> gaming_edge_accum = 0 ;
345+ state -> gaming_edge_last_reset = now ;
346+
347+ // If not moving toward switch, return early
348+ if (!moving_toward_switch )
349+ return NONE ;
350+ }
351+
352+ // Accumulate movement (use absolute value)
353+ state -> gaming_edge_accum += abs (offset_x );
354+
355+ // Check if threshold exceeded
356+ if (state -> gaming_edge_accum >= state -> config .gaming_edge_threshold ) {
357+ state -> gaming_edge_accum = 0 ;
358+ state -> gaming_edge_last_reset = now ;
359+ return switch_direction ;
360+ }
361+
362+ return NONE ;
363+ }
364+
320365void process_mouse_report (uint8_t * raw_report , int len , uint8_t itf , hid_interface_t * iface ) {
321366 mouse_values_t values = {0 };
322367 device_t * state = & global_state ;
@@ -327,6 +372,17 @@ void process_mouse_report(uint8_t *raw_report, int len, uint8_t itf, hid_interfa
327372 /* Calculate and update mouse pointer movement. */
328373 enum screen_pos_e switch_direction = update_mouse_position (state , & values );
329374
375+ /* Check for gaming mode edge switching */
376+ if (state -> gaming_mode && state -> config .gaming_edge_enabled ) {
377+ // Use the acceleration-adjusted offset from update_mouse_position
378+ output_t * current = & state -> config .output [state -> active_output ];
379+ uint8_t reduce_speed = state -> mouse_zoom ? MOUSE_ZOOM_SCALING_FACTOR : 0 ;
380+ float acceleration_factor = calculate_mouse_acceleration_factor (values .move_x , values .move_y );
381+ int offset_x = round (values .move_x * acceleration_factor * (current -> speed_x >> reduce_speed ));
382+
383+ switch_direction = check_gaming_edge_switch (state , offset_x );
384+ }
385+
330386 /* Create the report for the output PC based on the updated values */
331387 mouse_report_t report = create_mouse_report (state , & values );
332388
@@ -376,4 +432,4 @@ void queue_mouse_report(mouse_report_t *report, device_t *state) {
376432 return ;
377433
378434 queue_try_add (& state -> mouse_queue , report );
379- }
435+ }
0 commit comments