You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
/* copyright Constantin Fürst 2021, licensed under GPLv3, a copy is provided in LICENSE */ /* non-major portions of the code were taken from DWM (https://dwm.suckless.org) */ /* inspired and named after keym by Chris Willcocks (https://github.com/cwkx/keym) */
#include "typedefs.h"
#include <stdint.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
extern keym_state state;
/* internally-linked helpers */
static inline int enum_to_mouse_button(unsigned int val) { switch (val) { case MB_Left: return 1; case MB_Right: return 3; case MB_Middle: return 2; case MB_Back: return 8; case MB_Forward: return 9; default: return 0; } }
static inline uint32_t state_released(const uint32_t* a) { return (*a & KEY_RELEASE_MASK) >> 31; }
static inline uint32_t state_demasker(const uint32_t* a) { return *a & (~KEY_RELEASE_MASK); }
static inline int enum_to_scroll_button(uint32_t val) { switch(val) { case SD_Up: return 4; case SD_Down: return 5; default: return 0; } }
/* actual key-actions following */
void mouse_click(const uint32_t* a) { XTestFakeButtonEvent(state.display, enum_to_mouse_button(state_demasker(a)), !state_released(a), CurrentTime); }
void mouse_move(const uint32_t* a) { const unsigned int released = state_released(a);
switch (state_demasker(a)) { case MM_Up: state.y = released ? 0 : -1; break; case MM_Down: state.y = released ? 0 : 1; break; case MM_Left: state.x = released ? 0 : -1; break; case MM_Right: state.x = released ? 0 : 1; break; default: break; } }
void mouse_scroll(const uint32_t* a) { XTestFakeButtonEvent(state.display, enum_to_scroll_button(state_demasker(a)), state_released(a), 1); }
void control_action(const uint32_t* a) { const unsigned int released = state_released(a);
switch (state_demasker(a)) { case CA_QUIT_APPLICATION: state.quit = True; case CA_SPEED_HIGH: state.speed = released ? 1 : 0; break; case CA_SPEED_LOW: state.speed = released ? 1 : 2; break; default: break; } }
|