mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-04-18 23:06:48 +02:00
clang-format
This commit is contained in:
parent
34d6ce5566
commit
2747980a4e
13
drw.c
13
drw.c
@ -34,26 +34,25 @@ drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
|||||||
|
|
||||||
cairo_set_source_rgba(
|
cairo_set_source_rgba(
|
||||||
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
d->cairo, color.bgra[2] / (double)255, color.bgra[1] / (double)255,
|
||||||
color.bgra[0] / (double)255, color.bgra[3] / (double)255
|
color.bgra[0] / (double)255, color.bgra[3] / (double)255);
|
||||||
);
|
|
||||||
cairo_move_to(d->cairo, x + w / 2, y + h / 2);
|
cairo_move_to(d->cairo, x + w / 2, y + h / 2);
|
||||||
|
|
||||||
pango_layout_set_text(d->layout, label, -1);
|
pango_layout_set_text(d->layout, label, -1);
|
||||||
pango_layout_set_width(d->layout, (w - (b*2)) * PANGO_SCALE);
|
pango_layout_set_width(d->layout, (w - (b * 2)) * PANGO_SCALE);
|
||||||
pango_layout_set_height(d->layout, (h - (b*2)) * PANGO_SCALE);
|
pango_layout_set_height(d->layout, (h - (b * 2)) * PANGO_SCALE);
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
pango_layout_get_pixel_size(d->layout, &width, &height);
|
pango_layout_get_pixel_size(d->layout, &width, &height);
|
||||||
|
|
||||||
cairo_rel_move_to(d->cairo, - width / 2, - height / 2);
|
cairo_rel_move_to(d->cairo, -width / 2, -height / 2);
|
||||||
|
|
||||||
pango_cairo_show_layout(d->cairo, d->layout);
|
pango_cairo_show_layout(d->cairo, d->layout);
|
||||||
cairo_restore(d->cairo);
|
cairo_restore(d->cairo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y,
|
drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
|
||||||
uint32_t w, uint32_t h) {
|
uint32_t h) {
|
||||||
cairo_save(d->cairo);
|
cairo_save(d->cairo);
|
||||||
|
|
||||||
cairo_set_operator(d->cairo, CAIRO_OPERATOR_CLEAR);
|
cairo_set_operator(d->cairo, CAIRO_OPERATOR_CLEAR);
|
||||||
|
75
keyboard.c
75
keyboard.c
@ -29,9 +29,10 @@ kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
|
|||||||
kb->layer_index = layer_index;
|
kb->layer_index = layer_index;
|
||||||
kb->layout = l;
|
kb->layout = l;
|
||||||
if (kb->debug)
|
if (kb->debug)
|
||||||
fprintf(stderr, "Switching to layout %s, layer_index %ld\n", kb->layout->name, layer_index);
|
fprintf(stderr, "Switching to layout %s, layer_index %ld\n",
|
||||||
|
kb->layout->name, layer_index);
|
||||||
if (!l->keymap_name)
|
if (!l->keymap_name)
|
||||||
fprintf(stderr,"Layout has no keymap!"); //sanity check
|
fprintf(stderr, "Layout has no keymap!"); // sanity check
|
||||||
if ((!kb->prevlayout) ||
|
if ((!kb->prevlayout) ||
|
||||||
(strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
(strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||||
fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
|
fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
|
||||||
@ -43,26 +44,31 @@ kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
|
|||||||
void
|
void
|
||||||
kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
|
kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
|
||||||
size_t layer_index = kb->layer_index;
|
size_t layer_index = kb->layer_index;
|
||||||
if ((kb->mods & Ctrl) || (kb->mods & Alt) || (kb->mods & AltGr) || ((bool)kb->compose)) {
|
if ((kb->mods & Ctrl) || (kb->mods & Alt) || (kb->mods & AltGr) ||
|
||||||
|
((bool)kb->compose)) {
|
||||||
// with modifiers ctrl/alt/altgr: switch to the first layer
|
// with modifiers ctrl/alt/altgr: switch to the first layer
|
||||||
layer_index = 0;
|
layer_index = 0;
|
||||||
kb->mods = 0;
|
kb->mods = 0;
|
||||||
} else if ((kb->mods & Shift) || (kb->mods & CapsLock) || (invert)) {
|
} else if ((kb->mods & Shift) || (kb->mods & CapsLock) || (invert)) {
|
||||||
// with modifiers shift/capslock or invert set: switch to the previous layout in the layer sequence
|
// with modifiers shift/capslock or invert set: switch to the previous
|
||||||
|
// layout in the layer sequence
|
||||||
if (layer_index > 0) {
|
if (layer_index > 0) {
|
||||||
layer_index--;
|
layer_index--;
|
||||||
} else {
|
} else {
|
||||||
size_t layercount = 0;
|
size_t layercount = 0;
|
||||||
for (size_t i = 0; layercount == 0; i++) {
|
for (size_t i = 0; layercount == 0; i++) {
|
||||||
if (kb->landscape) {
|
if (kb->landscape) {
|
||||||
if (kb->landscape_layers[i] == NumLayouts) layercount = i;
|
if (kb->landscape_layers[i] == NumLayouts)
|
||||||
|
layercount = i;
|
||||||
} else {
|
} else {
|
||||||
if (kb->layers[i] == NumLayouts) layercount = i;
|
if (kb->layers[i] == NumLayouts)
|
||||||
|
layercount = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
layer_index = layercount - 1;
|
layer_index = layercount - 1;
|
||||||
}
|
}
|
||||||
if (!invert) kb->mods ^= Shift;
|
if (!invert)
|
||||||
|
kb->mods ^= Shift;
|
||||||
} else {
|
} else {
|
||||||
// normal behaviour: switch to the next layout in the layer sequence
|
// normal behaviour: switch to the next layout in the layer sequence
|
||||||
layer_index++;
|
layer_index++;
|
||||||
@ -70,9 +76,11 @@ kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
|
|||||||
size_t layercount = 0;
|
size_t layercount = 0;
|
||||||
for (size_t i = 0; layercount == 0; i++) {
|
for (size_t i = 0; layercount == 0; i++) {
|
||||||
if (kb->landscape) {
|
if (kb->landscape) {
|
||||||
if (kb->landscape_layers[i] == NumLayouts) layercount = i;
|
if (kb->landscape_layers[i] == NumLayouts)
|
||||||
|
layercount = i;
|
||||||
} else {
|
} else {
|
||||||
if (kb->layers[i] == NumLayouts) layercount = i;
|
if (kb->layers[i] == NumLayouts)
|
||||||
|
layercount = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (layer_index >= layercount) {
|
if (layer_index >= layercount) {
|
||||||
@ -146,8 +154,8 @@ kbd_init_layers(char *layer_names_list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
kbd_init(struct kbd *kb, struct layout *layouts,
|
kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
|
||||||
char *layer_names_list, char *landscape_layer_names_list) {
|
char *landscape_layer_names_list) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf(stderr, "Initializing keyboard\n");
|
fprintf(stderr, "Initializing keyboard\n");
|
||||||
@ -272,7 +280,7 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
|
|||||||
WL_KEYBOARD_KEY_STATE_RELEASED);
|
WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||||
} else {
|
} else {
|
||||||
if ((kb->last_press->code == KEY_SPACE) && (unlatch_shift)) {
|
if ((kb->last_press->code == KEY_SPACE) && (unlatch_shift)) {
|
||||||
//shift + space is tab
|
// shift + space is tab
|
||||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, KEY_TAB,
|
zwp_virtual_keyboard_v1_key(kb->vkbd, time, KEY_TAB,
|
||||||
WL_KEYBOARD_KEY_STATE_RELEASED);
|
WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||||
} else {
|
} else {
|
||||||
@ -342,7 +350,8 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
|
|||||||
void
|
void
|
||||||
kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
||||||
if ((kb->compose == 1) && (k->type != Compose) && (k->type != Mod)) {
|
if ((kb->compose == 1) && (k->type != Compose) && (k->type != Mod)) {
|
||||||
if ((k->type == NextLayer) || (k->type == BackLayer) || ((k->type == Code) && (k->code == KEY_SPACE))) {
|
if ((k->type == NextLayer) || (k->type == BackLayer) ||
|
||||||
|
((k->type == Code) && (k->code == KEY_SPACE))) {
|
||||||
kb->compose = 0;
|
kb->compose = 0;
|
||||||
if (kb->debug)
|
if (kb->debug)
|
||||||
fprintf(stderr, "showing layout index\n");
|
fprintf(stderr, "showing layout index\n");
|
||||||
@ -374,7 +383,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
kb->last_swipe = kb->last_press = k;
|
kb->last_swipe = kb->last_press = k;
|
||||||
kbd_draw_key(kb, k, Press);
|
kbd_draw_key(kb, k, Press);
|
||||||
if ((k->code == KEY_SPACE) && (kb->mods & Shift)) {
|
if ((k->code == KEY_SPACE) && (kb->mods & Shift)) {
|
||||||
//shift space is tab
|
// shift space is tab
|
||||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, 0, 0, 0, 0);
|
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, 0, 0, 0, 0);
|
||||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, KEY_TAB,
|
zwp_virtual_keyboard_v1_key(kb->vkbd, time, KEY_TAB,
|
||||||
WL_KEYBOARD_KEY_STATE_PRESSED);
|
WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||||
@ -406,7 +415,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
case Layout:
|
case Layout:
|
||||||
// switch to the layout determined by the key
|
// switch to the layout determined by the key
|
||||||
kbd_switch_layout(kb, k->layout, kbd_get_layer_index(kb, k->layout));
|
kbd_switch_layout(kb, k->layout, kbd_get_layer_index(kb, k->layout));
|
||||||
//reset previous layout to default/first so we don't get any weird cycles
|
// reset previous layout to default/first so we don't get any weird cycles
|
||||||
kb->last_abc_index = 0;
|
kb->last_abc_index = 0;
|
||||||
if (kb->landscape) {
|
if (kb->landscape) {
|
||||||
kb->last_abc_layout = &kb->layouts[kb->landscape_layers[0]];
|
kb->last_abc_layout = &kb->layouts[kb->landscape_layers[0]];
|
||||||
@ -427,15 +436,16 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
kbd_draw_key(kb, k, Unpress);
|
kbd_draw_key(kb, k, Unpress);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NextLayer: //(also handles previous layer when shift modifier is on, or "first layer" with other modifiers)
|
case NextLayer: //(also handles previous layer when shift modifier is on, or
|
||||||
|
//"first layer" with other modifiers)
|
||||||
kbd_next_layer(kb, k, false);
|
kbd_next_layer(kb, k, false);
|
||||||
break;
|
break;
|
||||||
case BackLayer: //triggered when "Abc" keys are pressed
|
case BackLayer: // triggered when "Abc" keys are pressed
|
||||||
// switch to the last active alphabetical layout
|
// switch to the last active alphabetical layout
|
||||||
if (kb->last_abc_layout) {
|
if (kb->last_abc_layout) {
|
||||||
kb->compose = 0;
|
kb->compose = 0;
|
||||||
kbd_switch_layout(kb, kb->last_abc_layout, kb->last_abc_index);
|
kbd_switch_layout(kb, kb->last_abc_layout, kb->last_abc_index);
|
||||||
//reset previous layout to default/first so we don't get any weird cycles
|
// reset previous layout to default/first so we don't get any weird cycles
|
||||||
kb->last_abc_index = 0;
|
kb->last_abc_index = 0;
|
||||||
if (kb->landscape) {
|
if (kb->landscape) {
|
||||||
kb->last_abc_layout = &kb->layouts[kb->landscape_layers[0]];
|
kb->last_abc_layout = &kb->layouts[kb->landscape_layers[0]];
|
||||||
@ -507,8 +517,10 @@ kbd_print_key_stdout(struct kbd *kb, struct key *k) {
|
|||||||
void
|
void
|
||||||
kbd_clear_last_popup(struct kbd *kb) {
|
kbd_clear_last_popup(struct kbd *kb) {
|
||||||
if (kb->last_popup_w && kb->last_popup_h) {
|
if (kb->last_popup_w && kb->last_popup_h) {
|
||||||
drw_do_clear(kb->popup_surf, kb->last_popup_x, kb->last_popup_y, kb->last_popup_w, kb->last_popup_h);
|
drw_do_clear(kb->popup_surf, kb->last_popup_x, kb->last_popup_y,
|
||||||
wl_surface_damage(kb->popup_surf->surf, kb->last_popup_x, kb->last_popup_y, kb->last_popup_w, kb->last_popup_h);
|
kb->last_popup_w, kb->last_popup_h);
|
||||||
|
wl_surface_damage(kb->popup_surf->surf, kb->last_popup_x, kb->last_popup_y,
|
||||||
|
kb->last_popup_w, kb->last_popup_h);
|
||||||
|
|
||||||
kb->last_popup_w = kb->last_popup_h = 0;
|
kb->last_popup_w = kb->last_popup_h = 0;
|
||||||
}
|
}
|
||||||
@ -531,11 +543,13 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
|
|||||||
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, scheme->high);
|
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, scheme->high);
|
||||||
break;
|
break;
|
||||||
case Swipe:
|
case Swipe:
|
||||||
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, scheme->swipe);
|
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||||
|
scheme->swipe);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, label);
|
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||||
|
label);
|
||||||
wl_surface_damage(kb->surf->surf, k->x, k->y, k->w, k->h);
|
wl_surface_damage(kb->surf->surf, k->x, k->y, k->w, k->h);
|
||||||
|
|
||||||
if (type == Press || type == Unpress) {
|
if (type == Press || type == Unpress) {
|
||||||
@ -546,9 +560,12 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
|
|||||||
kb->last_popup_w = k->w;
|
kb->last_popup_w = k->w;
|
||||||
kb->last_popup_h = k->h;
|
kb->last_popup_h = k->h;
|
||||||
|
|
||||||
drw_fill_rectangle(kb->popup_surf, kb->scheme.bg, k->x, kb->last_popup_y, k->w, k->h);
|
drw_fill_rectangle(kb->popup_surf, kb->scheme.bg, k->x, kb->last_popup_y,
|
||||||
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h, KBD_KEY_BORDER, scheme->high);
|
k->w, k->h);
|
||||||
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y, k->w, k->h, KBD_KEY_BORDER, label);
|
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
|
||||||
|
KBD_KEY_BORDER, scheme->high);
|
||||||
|
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y, k->w,
|
||||||
|
k->h, KBD_KEY_BORDER, label);
|
||||||
wl_surface_damage(kb->popup_surf->surf, k->x, kb->last_popup_y, k->w, k->h);
|
wl_surface_damage(kb->popup_surf->surf, k->x, kb->last_popup_y, k->w, k->h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -584,13 +601,15 @@ kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
|
|||||||
layoutcount);
|
layoutcount);
|
||||||
|
|
||||||
drwsurf_resize(kb->surf, kb->w, kb->h, kb->scale);
|
drwsurf_resize(kb->surf, kb->w, kb->h, kb->scale);
|
||||||
drwsurf_resize(kb->popup_surf, kb->w, kb->h*2, kb->scale);
|
drwsurf_resize(kb->popup_surf, kb->w, kb->h * 2, kb->scale);
|
||||||
for (int i = 0; i < layoutcount; i++) {
|
for (int i = 0; i < layoutcount; i++) {
|
||||||
if (kb->debug) {
|
if (kb->debug) {
|
||||||
if (layouts[i].name)
|
if (layouts[i].name)
|
||||||
fprintf(stderr, "Initialising layout %s, keymap %s\n", layouts[i].name, layouts[i].keymap_name);
|
fprintf(stderr, "Initialising layout %s, keymap %s\n", layouts[i].name,
|
||||||
|
layouts[i].keymap_name);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Initialising unnamed layout %d, keymap %s\n", i, layouts[i].keymap_name);
|
fprintf(stderr, "Initialising unnamed layout %d, keymap %s\n", i,
|
||||||
|
layouts[i].keymap_name);
|
||||||
}
|
}
|
||||||
kbd_init_layout(&layouts[i], kb->w, kb->h);
|
kbd_init_layout(&layouts[i], kb->w, kb->h);
|
||||||
}
|
}
|
||||||
|
160
main.c
160
main.c
@ -269,14 +269,15 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
|||||||
kbd_press_key(&keyboard, next_key, time);
|
kbd_press_key(&keyboard, next_key, time);
|
||||||
} else if (keyboard.compose) {
|
} else if (keyboard.compose) {
|
||||||
keyboard.compose = 0;
|
keyboard.compose = 0;
|
||||||
kbd_switch_layout(&keyboard, keyboard.prevlayout, keyboard.last_abc_index);
|
kbd_switch_layout(&keyboard, keyboard.prevlayout,
|
||||||
|
keyboard.last_abc_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
|
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
||||||
uint32_t time, uint32_t axis, wl_fixed_t value) {
|
uint32_t axis, wl_fixed_t value) {
|
||||||
kbd_next_layer(&keyboard, NULL, (value >= 0));
|
kbd_next_layer(&keyboard, NULL, (value >= 0));
|
||||||
drwsurf_flip(keyboard.surf);
|
drwsurf_flip(keyboard.surf);
|
||||||
}
|
}
|
||||||
@ -314,8 +315,8 @@ seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) {}
|
|||||||
void
|
void
|
||||||
wl_surface_enter(void *data, struct wl_surface *wl_surface,
|
wl_surface_enter(void *data, struct wl_surface *wl_surface,
|
||||||
struct wl_output *wl_output) {
|
struct wl_output *wl_output) {
|
||||||
for(int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
|
for (int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
|
||||||
if(wl_outputs[i].data == wl_output) {
|
if (wl_outputs[i].data == wl_output) {
|
||||||
current_output = &wl_outputs[i];
|
current_output = &wl_outputs[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -369,8 +370,7 @@ static const struct wl_output_listener output_listener = {
|
|||||||
.scale = display_handle_scale};
|
.scale = display_handle_scale};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
|
xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) {
|
||||||
{
|
|
||||||
xdg_wm_base_pong(xdg_wm_base, serial);
|
xdg_wm_base_pong(xdg_wm_base, serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
|||||||
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
||||||
draw_ctx.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
draw_ctx.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
||||||
} else if (strcmp(interface, "wl_output") == 0) {
|
} else if (strcmp(interface, "wl_output") == 0) {
|
||||||
if(wl_outputs_size < WL_OUTPUTS_LIMIT) {
|
if (wl_outputs_size < WL_OUTPUTS_LIMIT) {
|
||||||
struct Output *output = &wl_outputs[wl_outputs_size];
|
struct Output *output = &wl_outputs[wl_outputs_size];
|
||||||
output->data = wl_registry_bind(registry, name, &wl_output_interface, 2);
|
output->data = wl_registry_bind(registry, name, &wl_output_interface, 2);
|
||||||
output->name = name;
|
output->name = name;
|
||||||
@ -401,15 +401,14 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
|||||||
layer_shell =
|
layer_shell =
|
||||||
wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
|
wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
|
||||||
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
|
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
|
||||||
wm_base =
|
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
|
||||||
wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
|
|
||||||
xdg_wm_base_add_listener(wm_base, &xdg_wm_base_listener, NULL);
|
xdg_wm_base_add_listener(wm_base, &xdg_wm_base_listener, NULL);
|
||||||
} else if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) {
|
} else if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) ==
|
||||||
wfs_mgr =
|
0) {
|
||||||
wl_registry_bind(registry, name, &wp_fractional_scale_manager_v1_interface, 1);
|
wfs_mgr = wl_registry_bind(registry, name,
|
||||||
|
&wp_fractional_scale_manager_v1_interface, 1);
|
||||||
} else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
|
} else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
|
||||||
viewporter =
|
viewporter = wl_registry_bind(registry, name, &wp_viewporter_interface, 1);
|
||||||
wl_registry_bind(registry, name, &wp_viewporter_interface, 1);
|
|
||||||
} else if (strcmp(interface,
|
} else if (strcmp(interface,
|
||||||
zwp_virtual_keyboard_manager_v1_interface.name) == 0) {
|
zwp_virtual_keyboard_manager_v1_interface.name) == 0) {
|
||||||
vkbd_mgr = wl_registry_bind(registry, name,
|
vkbd_mgr = wl_registry_bind(registry, name,
|
||||||
@ -419,10 +418,10 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
|||||||
|
|
||||||
void
|
void
|
||||||
handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||||
for(int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
|
for (int i = 0; i < WL_OUTPUTS_LIMIT; i += 1) {
|
||||||
if(wl_outputs[i].name == name) {
|
if (wl_outputs[i].name == name) {
|
||||||
wl_output_destroy(wl_outputs[i].data);
|
wl_output_destroy(wl_outputs[i].data);
|
||||||
for(; i < WL_OUTPUTS_LIMIT - 1; i += 1) {
|
for (; i < WL_OUTPUTS_LIMIT - 1; i += 1) {
|
||||||
wl_outputs[i] = wl_outputs[i + 1];
|
wl_outputs[i] = wl_outputs[i + 1];
|
||||||
}
|
}
|
||||||
wl_outputs_size -= 1;
|
wl_outputs_size -= 1;
|
||||||
@ -432,9 +431,8 @@ handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_popup_surface_configure(void *data,
|
xdg_popup_surface_configure(void *data, struct xdg_surface *xdg_surface,
|
||||||
struct xdg_surface *xdg_surface, uint32_t serial)
|
uint32_t serial) {
|
||||||
{
|
|
||||||
xdg_surface_ack_configure(xdg_surface, serial);
|
xdg_surface_ack_configure(xdg_surface, serial);
|
||||||
drwsurf_flip(&popup_draw_surf);
|
drwsurf_flip(&popup_draw_surf);
|
||||||
}
|
}
|
||||||
@ -443,21 +441,16 @@ static const struct xdg_surface_listener xdg_popup_surface_listener = {
|
|||||||
.configure = xdg_popup_surface_configure,
|
.configure = xdg_popup_surface_configure,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_popup_configure(void *data,
|
xdg_popup_configure(void *data, struct xdg_popup *xdg_popup, int32_t x,
|
||||||
struct xdg_popup *xdg_popup,
|
int32_t y, int32_t width, int32_t height) {
|
||||||
int32_t x, int32_t y,
|
|
||||||
int32_t width, int32_t height)
|
|
||||||
{
|
|
||||||
kbd_resize(&keyboard, layouts, NumLayouts);
|
kbd_resize(&keyboard, layouts, NumLayouts);
|
||||||
|
|
||||||
drwsurf_flip(&draw_surf);
|
drwsurf_flip(&draw_surf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_popup_done(void *data, struct xdg_popup *xdg_popup) {
|
xdg_popup_done(void *data, struct xdg_popup *xdg_popup) {}
|
||||||
}
|
|
||||||
|
|
||||||
static const struct xdg_popup_listener xdg_popup_listener = {
|
static const struct xdg_popup_listener xdg_popup_listener = {
|
||||||
.configure = xdg_popup_configure,
|
.configure = xdg_popup_configure,
|
||||||
@ -465,14 +458,14 @@ static const struct xdg_popup_listener xdg_popup_listener = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wp_fractional_scale_prefered_scale(void *data,
|
wp_fractional_scale_prefered_scale(
|
||||||
struct wp_fractional_scale_v1 *wp_fractional_scale_v1,
|
void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1,
|
||||||
uint32_t scale)
|
uint32_t scale) {
|
||||||
{
|
|
||||||
keyboard.pending_scale = (double)scale / 120;
|
keyboard.pending_scale = (double)scale / 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wp_fractional_scale_v1_listener wp_fractional_scale_listener = {
|
static const struct wp_fractional_scale_v1_listener
|
||||||
|
wp_fractional_scale_listener = {
|
||||||
.preferred_scale = wp_fractional_scale_prefered_scale,
|
.preferred_scale = wp_fractional_scale_prefered_scale,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -509,18 +502,22 @@ resize() {
|
|||||||
void
|
void
|
||||||
layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
|
layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
|
||||||
uint32_t serial, uint32_t w, uint32_t h) {
|
uint32_t serial, uint32_t w, uint32_t h) {
|
||||||
if (keyboard.w != w || keyboard.h != h || keyboard.scale != keyboard.pending_scale) {
|
if (keyboard.w != w || keyboard.h != h ||
|
||||||
|
keyboard.scale != keyboard.pending_scale) {
|
||||||
keyboard.w = w;
|
keyboard.w = w;
|
||||||
keyboard.h = h;
|
keyboard.h = h;
|
||||||
keyboard.scale = keyboard.pending_scale;
|
keyboard.scale = keyboard.pending_scale;
|
||||||
|
|
||||||
if (wfs_mgr && viewporter) {
|
if (wfs_mgr && viewporter) {
|
||||||
if (!wfs_draw_surf) {
|
if (!wfs_draw_surf) {
|
||||||
wfs_draw_surf = wp_fractional_scale_manager_v1_get_fractional_scale(wfs_mgr, draw_surf.surf);
|
wfs_draw_surf = wp_fractional_scale_manager_v1_get_fractional_scale(
|
||||||
wp_fractional_scale_v1_add_listener(wfs_draw_surf, &wp_fractional_scale_listener, NULL);
|
wfs_mgr, draw_surf.surf);
|
||||||
|
wp_fractional_scale_v1_add_listener(
|
||||||
|
wfs_draw_surf, &wp_fractional_scale_listener, NULL);
|
||||||
}
|
}
|
||||||
if (!draw_surf_viewport) {
|
if (!draw_surf_viewport) {
|
||||||
draw_surf_viewport = wp_viewporter_get_viewport(viewporter, draw_surf.surf);
|
draw_surf_viewport =
|
||||||
|
wp_viewporter_get_viewport(viewporter, draw_surf.surf);
|
||||||
}
|
}
|
||||||
wp_viewport_set_destination(draw_surf_viewport, keyboard.w, keyboard.h);
|
wp_viewport_set_destination(draw_surf_viewport, keyboard.w, keyboard.h);
|
||||||
} else {
|
} else {
|
||||||
@ -539,19 +536,24 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
|
|||||||
|
|
||||||
popup_draw_surf.surf = wl_compositor_create_surface(compositor);
|
popup_draw_surf.surf = wl_compositor_create_surface(compositor);
|
||||||
|
|
||||||
xdg_positioner_set_size(popup_xdg_positioner, w, h*2);
|
xdg_positioner_set_size(popup_xdg_positioner, w, h * 2);
|
||||||
xdg_positioner_set_anchor_rect(popup_xdg_positioner, 0, -h, w, h*2);
|
xdg_positioner_set_anchor_rect(popup_xdg_positioner, 0, -h, w, h * 2);
|
||||||
|
|
||||||
wl_surface_set_input_region(popup_draw_surf.surf, empty_region);
|
wl_surface_set_input_region(popup_draw_surf.surf, empty_region);
|
||||||
popup_xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, popup_draw_surf.surf);
|
popup_xdg_surface =
|
||||||
xdg_surface_add_listener(popup_xdg_surface, &xdg_popup_surface_listener, NULL);
|
xdg_wm_base_get_xdg_surface(wm_base, popup_draw_surf.surf);
|
||||||
popup_xdg_popup = xdg_surface_get_popup(popup_xdg_surface, NULL, popup_xdg_positioner);
|
xdg_surface_add_listener(popup_xdg_surface, &xdg_popup_surface_listener,
|
||||||
|
NULL);
|
||||||
|
popup_xdg_popup =
|
||||||
|
xdg_surface_get_popup(popup_xdg_surface, NULL, popup_xdg_positioner);
|
||||||
xdg_popup_add_listener(popup_xdg_popup, &xdg_popup_listener, NULL);
|
xdg_popup_add_listener(popup_xdg_popup, &xdg_popup_listener, NULL);
|
||||||
zwlr_layer_surface_v1_get_popup(layer_surface, popup_xdg_popup);
|
zwlr_layer_surface_v1_get_popup(layer_surface, popup_xdg_popup);
|
||||||
|
|
||||||
if (wfs_mgr && viewporter) {
|
if (wfs_mgr && viewporter) {
|
||||||
popup_draw_surf_viewport = wp_viewporter_get_viewport(viewporter, popup_draw_surf.surf);
|
popup_draw_surf_viewport =
|
||||||
wp_viewport_set_destination(popup_draw_surf_viewport, keyboard.w, keyboard.h * 2);
|
wp_viewporter_get_viewport(viewporter, popup_draw_surf.surf);
|
||||||
|
wp_viewport_set_destination(popup_draw_surf_viewport, keyboard.w,
|
||||||
|
keyboard.h * 2);
|
||||||
} else {
|
} else {
|
||||||
wl_surface_set_buffer_scale(popup_draw_surf.surf, keyboard.scale);
|
wl_surface_set_buffer_scale(popup_draw_surf.surf, keyboard.scale);
|
||||||
}
|
}
|
||||||
@ -578,24 +580,34 @@ usage(char *argv0) {
|
|||||||
fprintf(stderr, "Options:\n");
|
fprintf(stderr, "Options:\n");
|
||||||
fprintf(stderr, " -D - Enable debug\n");
|
fprintf(stderr, " -D - Enable debug\n");
|
||||||
fprintf(stderr, " -o - Print pressed keys to standard output\n");
|
fprintf(stderr, " -o - Print pressed keys to standard output\n");
|
||||||
fprintf(stderr, " -O - Print intersected keys to standard output\n");
|
fprintf(stderr,
|
||||||
|
" -O - Print intersected keys to standard output\n");
|
||||||
fprintf(stderr, " -H [int] - Height in pixels\n");
|
fprintf(stderr, " -H [int] - Height in pixels\n");
|
||||||
fprintf(stderr, " -L [int] - Landscape height in pixels\n");
|
fprintf(stderr, " -L [int] - Landscape height in pixels\n");
|
||||||
fprintf(stderr, " --fn [font] - Set font (e.g: DejaVu Sans 20)\n");
|
fprintf(stderr, " --fn [font] - Set font (e.g: DejaVu Sans 20)\n");
|
||||||
fprintf(stderr, " --hidden - Start hidden (send SIGUSR2 to show)\n");
|
fprintf(stderr, " --hidden - Start hidden (send SIGUSR2 to show)\n");
|
||||||
fprintf(stderr, " --alpha [int] - Set alpha value for all colors [0-255]\n");
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
" --alpha [int] - Set alpha value for all colors [0-255]\n");
|
||||||
fprintf(stderr, " --bg [rrggbb|aa] - Set color of background\n");
|
fprintf(stderr, " --bg [rrggbb|aa] - Set color of background\n");
|
||||||
fprintf(stderr, " --fg [rrggbb|aa] - Set color of keys\n");
|
fprintf(stderr, " --fg [rrggbb|aa] - Set color of keys\n");
|
||||||
fprintf(stderr, " --fg-sp [rrggbb|aa] - Set color of special keys\n");
|
fprintf(stderr, " --fg-sp [rrggbb|aa] - Set color of special keys\n");
|
||||||
fprintf(stderr, " --press [rrggbb|aa] - Set color of pressed keys\n");
|
fprintf(stderr, " --press [rrggbb|aa] - Set color of pressed keys\n");
|
||||||
fprintf(stderr, " --press-sp [rrggbb|aa] - Set color of pressed special keys\n");
|
fprintf(stderr,
|
||||||
|
" --press-sp [rrggbb|aa] - Set color of pressed special keys\n");
|
||||||
fprintf(stderr, " --swipe [rrggbb|aa] - Set color of swiped keys\n");
|
fprintf(stderr, " --swipe [rrggbb|aa] - Set color of swiped keys\n");
|
||||||
fprintf(stderr, " --swipe-sp [rrggbb|aa] - Set color of swiped special keys\n");
|
fprintf(stderr,
|
||||||
|
" --swipe-sp [rrggbb|aa] - Set color of swiped special keys\n");
|
||||||
fprintf(stderr, " --text [rrggbb|aa] - Set color of text on keys\n");
|
fprintf(stderr, " --text [rrggbb|aa] - Set color of text on keys\n");
|
||||||
fprintf(stderr, " --text-sp [rrggbb|aa] - Set color of text on special keys\n");
|
fprintf(stderr,
|
||||||
fprintf(stderr, " --list-layers - Print the list of available layers\n");
|
" --text-sp [rrggbb|aa] - Set color of text on special keys\n");
|
||||||
fprintf(stderr, " -l - Comma separated list of layers\n");
|
fprintf(stderr,
|
||||||
fprintf(stderr, " --landscape-layers - Comma separated list of landscape layers\n");
|
" --list-layers - Print the list of available layers\n");
|
||||||
|
fprintf(stderr,
|
||||||
|
" -l - Comma separated list of layers\n");
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
" --landscape-layers - Comma separated list of landscape layers\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -646,8 +658,10 @@ show() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
toggle_visibility() {
|
toggle_visibility() {
|
||||||
if (hidden) show();
|
if (hidden)
|
||||||
else hide();
|
show();
|
||||||
|
else
|
||||||
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -656,19 +670,19 @@ pipewarn() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
set_kbd_colors(uint8_t * bgra, char * hex) {
|
set_kbd_colors(uint8_t *bgra, char *hex) {
|
||||||
// bg, fg, text, high, swipe
|
// bg, fg, text, high, swipe
|
||||||
int length = strlen(hex);
|
int length = strlen(hex);
|
||||||
if (length == 6 || length == 8) {
|
if (length == 6 || length == 8) {
|
||||||
char subhex[2];
|
char subhex[2];
|
||||||
memcpy(subhex, hex, 2);
|
memcpy(subhex, hex, 2);
|
||||||
bgra[2] = (int)strtol(subhex, NULL, 16);
|
bgra[2] = (int)strtol(subhex, NULL, 16);
|
||||||
memcpy(subhex, hex+2, 2);
|
memcpy(subhex, hex + 2, 2);
|
||||||
bgra[1] = (int)strtol(subhex, NULL, 16);
|
bgra[1] = (int)strtol(subhex, NULL, 16);
|
||||||
memcpy(subhex, hex+4, 2);
|
memcpy(subhex, hex + 4, 2);
|
||||||
bgra[0] = (int)strtol(subhex, NULL, 16);
|
bgra[0] = (int)strtol(subhex, NULL, 16);
|
||||||
if (length == 8) {
|
if (length == 8) {
|
||||||
memcpy(subhex, hex+6, 2);
|
memcpy(subhex, hex + 6, 2);
|
||||||
bgra[3] = (int)strtol(subhex, NULL, 16);
|
bgra[3] = (int)strtol(subhex, NULL, 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -759,7 +773,8 @@ main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
set_kbd_colors(keyboard.scheme.high.bgra, argv[++i]);
|
set_kbd_colors(keyboard.scheme.high.bgra, argv[++i]);
|
||||||
} else if ((!strcmp(argv[i], "-press-sp")) || (!strcmp(argv[i], "--press-sp"))) {
|
} else if ((!strcmp(argv[i], "-press-sp")) ||
|
||||||
|
(!strcmp(argv[i], "--press-sp"))) {
|
||||||
if (i >= argc - 1) {
|
if (i >= argc - 1) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -771,7 +786,8 @@ main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
set_kbd_colors(keyboard.scheme.swipe.bgra, argv[++i]);
|
set_kbd_colors(keyboard.scheme.swipe.bgra, argv[++i]);
|
||||||
} else if ((!strcmp(argv[i], "-swipe-sp")) || (!strcmp(argv[i], "--swipe-sp"))) {
|
} else if ((!strcmp(argv[i], "-swipe-sp")) ||
|
||||||
|
(!strcmp(argv[i], "--swipe-sp"))) {
|
||||||
if (i >= argc - 1) {
|
if (i >= argc - 1) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -783,7 +799,8 @@ main(int argc, char **argv) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
set_kbd_colors(keyboard.scheme.text.bgra, argv[++i]);
|
set_kbd_colors(keyboard.scheme.text.bgra, argv[++i]);
|
||||||
} else if ((!strcmp(argv[i], "-text-sp")) || (!strcmp(argv[i], "--text-sp"))) {
|
} else if ((!strcmp(argv[i], "-text-sp")) ||
|
||||||
|
(!strcmp(argv[i], "--text-sp"))) {
|
||||||
if (i >= argc - 1) {
|
if (i >= argc - 1) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -879,13 +896,14 @@ main(int argc, char **argv) {
|
|||||||
die("failed to init virtual keyboard_manager\n");
|
die("failed to init virtual keyboard_manager\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
kbd_init(&keyboard, (struct layout *)&layouts,
|
kbd_init(&keyboard, (struct layout *)&layouts, layer_names_list,
|
||||||
layer_names_list, landscape_layer_names_list);
|
landscape_layer_names_list);
|
||||||
|
|
||||||
draw_ctx.font_description =
|
draw_ctx.font_description =
|
||||||
pango_font_description_from_string(fc_font_pattern);
|
pango_font_description_from_string(fc_font_pattern);
|
||||||
|
|
||||||
if (!hidden) show();
|
if (!hidden)
|
||||||
|
show();
|
||||||
|
|
||||||
struct pollfd fds[2];
|
struct pollfd fds[2];
|
||||||
int WAYLAND_FD = 0;
|
int WAYLAND_FD = 0;
|
||||||
@ -925,10 +943,14 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (read(fds[SIGNAL_FD].fd, &si, sizeof(si)) != sizeof(si))
|
if (read(fds[SIGNAL_FD].fd, &si, sizeof(si)) != sizeof(si))
|
||||||
fprintf(stderr, "Signal read error: %d", errno);
|
fprintf(stderr, "Signal read error: %d", errno);
|
||||||
else if (si.ssi_signo == SIGUSR1) hide();
|
else if (si.ssi_signo == SIGUSR1)
|
||||||
else if (si.ssi_signo == SIGUSR2) show();
|
hide();
|
||||||
else if (si.ssi_signo == SIGRTMIN) toggle_visibility();
|
else if (si.ssi_signo == SIGUSR2)
|
||||||
else if (si.ssi_signo == SIGPIPE) pipewarn();
|
show();
|
||||||
|
else if (si.ssi_signo == SIGRTMIN)
|
||||||
|
toggle_visibility();
|
||||||
|
else if (si.ssi_signo == SIGPIPE)
|
||||||
|
pipewarn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user