parent
470b4dfbae
commit
5ff0619ca1
@ -0,0 +1,49 @@
|
|||||||
|
#ifndef _SWAY_KEY_STATE_H
|
||||||
|
#define _SWAY_KEY_STATE_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "container.h"
|
||||||
|
|
||||||
|
/* Keyboard state */
|
||||||
|
|
||||||
|
typedef uint32_t keycode;
|
||||||
|
|
||||||
|
// returns true if key has been pressed, otherwise false
|
||||||
|
bool check_key(keycode key);
|
||||||
|
|
||||||
|
// sets a key as pressed
|
||||||
|
void press_key(keycode key);
|
||||||
|
|
||||||
|
// unsets a key as pressed
|
||||||
|
void release_key(keycode key);
|
||||||
|
|
||||||
|
/* Pointer state */
|
||||||
|
|
||||||
|
enum pointer_values {
|
||||||
|
M_LEFT_CLICK = 272,
|
||||||
|
M_RIGHT_CLICK = 273,
|
||||||
|
M_SCROLL_CLICK = 274,
|
||||||
|
M_SCROLL_UP = 275,
|
||||||
|
M_SCROLL_DOWN = 276,
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct pointer_state {
|
||||||
|
bool l_held;
|
||||||
|
bool r_held;
|
||||||
|
struct pointer_floating {
|
||||||
|
bool drag;
|
||||||
|
bool resize;
|
||||||
|
} floating;
|
||||||
|
struct pointer_lock {
|
||||||
|
bool left;
|
||||||
|
bool right;
|
||||||
|
bool top;
|
||||||
|
bool bottom;
|
||||||
|
} lock;
|
||||||
|
} pointer_state;
|
||||||
|
|
||||||
|
void start_floating(swayc_t *view);
|
||||||
|
void reset_floating(swayc_t *view);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef _SWAY_KEY_STATE_H
|
|
||||||
#define _SWAY_KEY_STATE_H
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
typedef uint32_t keycode;
|
|
||||||
|
|
||||||
// returns true if key has been pressed, otherwise false
|
|
||||||
bool check_key(keycode key);
|
|
||||||
|
|
||||||
// sets a key as pressed
|
|
||||||
void press_key(keycode key);
|
|
||||||
|
|
||||||
// unsets a key as pressed
|
|
||||||
void release_key(keycode key);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "input_state.h"
|
||||||
|
|
||||||
|
enum { KEY_STATE_MAX_LENGTH = 64 };
|
||||||
|
|
||||||
|
static keycode key_state_array[KEY_STATE_MAX_LENGTH];
|
||||||
|
static uint8_t key_state_length = 0;
|
||||||
|
|
||||||
|
static uint8_t find_key(keycode key) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < key_state_length; ++i) {
|
||||||
|
if (key_state_array[i] == key) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_key(keycode key) {
|
||||||
|
return find_key(key) < key_state_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void press_key(keycode key) {
|
||||||
|
// Check if key exists
|
||||||
|
if (!check_key(key)) {
|
||||||
|
// Check that we dont exceed buffer length
|
||||||
|
if (key_state_length < KEY_STATE_MAX_LENGTH) {
|
||||||
|
key_state_array[key_state_length++] = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void release_key(keycode key) {
|
||||||
|
uint8_t index = find_key(key);
|
||||||
|
if (index < key_state_length) {
|
||||||
|
//shift it over and remove key
|
||||||
|
memmove(&key_state_array[index],
|
||||||
|
&key_state_array[index + 1],
|
||||||
|
sizeof(*key_state_array) * (--key_state_length - index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0, 0}};
|
||||||
|
|
||||||
|
static struct wlc_geometry saved_floating;
|
||||||
|
|
||||||
|
void start_floating(swayc_t *view) {
|
||||||
|
if (view->is_floating) {
|
||||||
|
saved_floating.origin.x = view->x;
|
||||||
|
saved_floating.origin.y = view->y;
|
||||||
|
saved_floating.size.w = view->width;
|
||||||
|
saved_floating.size.h = view->height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_floating(swayc_t *view) {
|
||||||
|
if (view->is_floating) {
|
||||||
|
view->x = saved_floating.origin.x;
|
||||||
|
view->y = saved_floating.origin.y;
|
||||||
|
view->width = saved_floating.size.w;
|
||||||
|
view->height = saved_floating.size.h;
|
||||||
|
arrange_windows(view->parent, -1, -1);
|
||||||
|
}
|
||||||
|
pointer_state.floating = (struct pointer_floating){0,0};
|
||||||
|
pointer_state.lock = (struct pointer_lock){0,0,0,0};
|
||||||
|
}
|
||||||
|
|
@ -1,52 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include "key_state.h"
|
|
||||||
|
|
||||||
enum { KEY_STATE_MAX_LENGTH = 64 };
|
|
||||||
|
|
||||||
static keycode key_state_array[KEY_STATE_MAX_LENGTH];
|
|
||||||
static uint8_t key_state_length = 0;
|
|
||||||
|
|
||||||
static uint8_t find_key(keycode key)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < key_state_length; ++i)
|
|
||||||
{
|
|
||||||
if (key_state_array[i] == key)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool check_key(keycode key)
|
|
||||||
{
|
|
||||||
return find_key(key) < key_state_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
void press_key(keycode key)
|
|
||||||
{
|
|
||||||
// Check if key exists
|
|
||||||
if (!check_key(key))
|
|
||||||
{
|
|
||||||
// Check that we dont exceed buffer length
|
|
||||||
if (key_state_length < KEY_STATE_MAX_LENGTH) {
|
|
||||||
key_state_array[key_state_length++] = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void release_key(keycode key)
|
|
||||||
{
|
|
||||||
uint8_t index = find_key(key);
|
|
||||||
if (index < key_state_length)
|
|
||||||
{
|
|
||||||
//shift it over and remove key
|
|
||||||
memmove(&key_state_array[index],
|
|
||||||
&key_state_array[index + 1],
|
|
||||||
sizeof(*key_state_array) * (--key_state_length - index));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue