Simplest clang-format

This commit is contained in:
Willow Barraco 2023-09-08 22:56:50 +02:00
parent 2747980a4e
commit fbbf563d70
No known key found for this signature in database
GPG Key ID: EABA44759877E02A
6 changed files with 1476 additions and 1626 deletions

View File

@ -1,107 +1,2 @@
--- BasedOnStyle: LLVM
Language: Cpp IndentWidth: 4
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 2
UseTab: ForIndentation
...

33
drw.c
View File

@ -5,8 +5,7 @@
#include "drw.h" #include "drw.h"
#include "shm_open.h" #include "shm_open.h"
void void drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
if (ds->buf) { if (ds->buf) {
munmap(ds->pool_data, ds->size); munmap(ds->pool_data, ds->size);
wl_buffer_destroy(ds->buf); wl_buffer_destroy(ds->buf);
@ -20,14 +19,12 @@ drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
setup_buffer(ds); setup_buffer(ds);
} }
void void drwsurf_flip(struct drwsurf *ds) {
drwsurf_flip(struct drwsurf *ds) {
wl_surface_attach(ds->surf, ds->buf, 0, 0); wl_surface_attach(ds->surf, ds->buf, 0, 0);
wl_surface_commit(ds->surf); wl_surface_commit(ds->surf);
} }
void void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h, uint32_t b, const char *label) { uint32_t w, uint32_t h, uint32_t b, const char *label) {
cairo_save(d->cairo); cairo_save(d->cairo);
@ -50,8 +47,7 @@ drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
cairo_restore(d->cairo); cairo_restore(d->cairo);
} }
void void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
uint32_t h) { uint32_t h) {
cairo_save(d->cairo); cairo_save(d->cairo);
@ -62,8 +58,7 @@ drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
cairo_restore(d->cairo); cairo_restore(d->cairo);
} }
void void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h, bool over) { uint32_t w, uint32_t h, bool over) {
cairo_save(d->cairo); cairo_save(d->cairo);
@ -82,20 +77,17 @@ drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
cairo_restore(d->cairo); cairo_restore(d->cairo);
} }
void void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h) { uint32_t w, uint32_t h) {
drw_do_rectangle(d, color, x, y, w, h, false); drw_do_rectangle(d, color, x, y, w, h, false);
} }
void void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h) { uint32_t w, uint32_t h) {
drw_do_rectangle(d, color, x, y, w, h, true); drw_do_rectangle(d, color, x, y, w, h, true);
} }
uint32_t uint32_t setup_buffer(struct drwsurf *drwsurf) {
setup_buffer(struct drwsurf *drwsurf) {
int stride = drwsurf->width * 4; int stride = drwsurf->width * 4;
drwsurf->size = stride * drwsurf->height; drwsurf->size = stride * drwsurf->height;
@ -113,14 +105,15 @@ setup_buffer(struct drwsurf *drwsurf) {
struct wl_shm_pool *pool = struct wl_shm_pool *pool =
wl_shm_create_pool(drwsurf->ctx->shm, fd, drwsurf->size); wl_shm_create_pool(drwsurf->ctx->shm, fd, drwsurf->size);
drwsurf->buf = wl_shm_pool_create_buffer( drwsurf->buf =
pool, 0, drwsurf->width, drwsurf->height, stride, WL_SHM_FORMAT_ARGB8888); wl_shm_pool_create_buffer(pool, 0, drwsurf->width, drwsurf->height,
stride, WL_SHM_FORMAT_ARGB8888);
wl_shm_pool_destroy(pool); wl_shm_pool_destroy(pool);
close(fd); close(fd);
cairo_surface_t *s = cairo_image_surface_create_for_data( cairo_surface_t *s = cairo_image_surface_create_for_data(
drwsurf->pool_data, CAIRO_FORMAT_ARGB32, drwsurf->width, drwsurf->height, drwsurf->pool_data, CAIRO_FORMAT_ARGB32, drwsurf->width,
stride); drwsurf->height, stride);
drwsurf->cairo = cairo_create(s); drwsurf->cairo = cairo_create(s);
cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale); cairo_scale(drwsurf->cairo, drwsurf->scale, drwsurf->scale);

View File

@ -1,11 +1,11 @@
#include "keyboard.h"
#include "drw.h"
#include "os-compatibility.h"
#include "proto/virtual-keyboard-unstable-v1-client-protocol.h" #include "proto/virtual-keyboard-unstable-v1-client-protocol.h"
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "keyboard.h"
#include "drw.h"
#include "os-compatibility.h"
#define MAX_LAYERS 25 #define MAX_LAYERS 25
@ -19,8 +19,7 @@
#endif #endif
#include KEYMAP #include KEYMAP
void void kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
kb->prevlayout = kb->layout; kb->prevlayout = kb->layout;
if ((kb->layer_index != kb->last_abc_index) && (kb->layout->abc)) { if ((kb->layer_index != kb->last_abc_index) && (kb->layout->abc)) {
kb->last_abc_layout = kb->layout; kb->last_abc_layout = kb->layout;
@ -41,8 +40,7 @@ kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
kbd_draw_layout(kb); kbd_draw_layout(kb);
} }
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) || if ((kb->mods & Ctrl) || (kb->mods & Alt) || (kb->mods & AltGr) ||
((bool)kb->compose)) { ((bool)kb->compose)) {
@ -50,8 +48,8 @@ kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
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 // with modifiers shift/capslock or invert set: switch to the
// layout in the layer sequence // previous layout in the layer sequence
if (layer_index > 0) { if (layer_index > 0) {
layer_index--; layer_index--;
} else { } else {
@ -70,7 +68,8 @@ kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
if (!invert) if (!invert)
kb->mods ^= Shift; 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++;
} }
size_t layercount = 0; size_t layercount = 0;
@ -101,8 +100,7 @@ kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
kbd_switch_layout(kb, &kb->layouts[layer], layer_index); kbd_switch_layout(kb, &kb->layouts[layer], layer_index);
} }
uint8_t uint8_t kbd_get_rows(struct layout *l) {
kbd_get_rows(struct layout *l) {
uint8_t rows = 0; uint8_t rows = 0;
struct key *k = l->keys; struct key *k = l->keys;
while (k->type != Last) { while (k->type != Last) {
@ -114,8 +112,7 @@ kbd_get_rows(struct layout *l) {
return rows + 1; return rows + 1;
} }
enum layout_id * enum layout_id *kbd_init_layers(char *layer_names_list) {
kbd_init_layers(char *layer_names_list) {
enum layout_id *layers; enum layout_id *layers;
uint8_t numlayers = 0; uint8_t numlayers = 0;
bool found; bool found;
@ -153,8 +150,7 @@ kbd_init_layers(char *layer_names_list) {
return layers; return layers;
} }
void void kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
char *landscape_layer_names_list) { char *landscape_layer_names_list) {
int i; int i;
@ -195,8 +191,7 @@ kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
create_and_upload_keymap(kb, kb->layout->keymap_name, 0, 0); create_and_upload_keymap(kb, kb->layout->keymap_name, 0, 0);
} }
void void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
uint32_t x = 0, y = 0; uint32_t x = 0, y = 0;
uint8_t rows = kbd_get_rows(l); uint8_t rows = kbd_get_rows(l);
@ -227,8 +222,7 @@ kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
} }
} }
double double kbd_get_row_length(struct key *k) {
kbd_get_row_length(struct key *k) {
double l = 0.0; double l = 0.0;
while ((k->type != Last) && (k->type != EndRow)) { while ((k->type != Last) && (k->type != EndRow)) {
l += k->width; l += k->width;
@ -237,15 +231,15 @@ kbd_get_row_length(struct key *k) {
return l; return l;
} }
struct key * struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
struct layout *l = kb->layout; struct layout *l = kb->layout;
struct key *k = l->keys; struct key *k = l->keys;
if (kb->debug) if (kb->debug)
fprintf(stderr, "get key: +%d+%d\n", x, y); fprintf(stderr, "get key: +%d+%d\n", x, y);
while (k->type != Last) { while (k->type != Last) {
if ((k->type != EndRow) && (k->type != Pad) && (k->type != Pad) && if ((k->type != EndRow) && (k->type != Pad) && (k->type != Pad) &&
(x >= k->x) && (y >= k->y) && (x < k->x + k->w) && (y < k->y + k->h)) { (x >= k->x) && (y >= k->y) && (x < k->x + k->w) &&
(y < k->y + k->h)) {
return k; return k;
} }
k++; k++;
@ -253,8 +247,7 @@ kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
return NULL; return NULL;
} }
size_t size_t kbd_get_layer_index(struct kbd *kb, struct layout *l) {
kbd_get_layer_index(struct kbd *kb, struct layout *l) {
for (size_t i = 0; i < NumLayouts - 1; i++) { for (size_t i = 0; i < NumLayouts - 1; i++) {
if (l == &kb->layouts[i]) { if (l == &kb->layouts[i]) {
return i; return i;
@ -263,8 +256,7 @@ kbd_get_layer_index(struct kbd *kb, struct layout *l) {
return 0; return 0;
} }
void void kbd_unpress_key(struct kbd *kb, uint32_t time) {
kbd_unpress_key(struct kbd *kb, uint32_t time) {
bool unlatch_shift = false; bool unlatch_shift = false;
if (kb->last_press) { if (kb->last_press) {
@ -284,7 +276,8 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
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 {
zwp_virtual_keyboard_v1_key(kb->vkbd, time, kb->last_press->code, zwp_virtual_keyboard_v1_key(kb->vkbd, time,
kb->last_press->code,
WL_KEYBOARD_KEY_STATE_RELEASED); WL_KEYBOARD_KEY_STATE_RELEASED);
} }
} }
@ -302,8 +295,7 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
} }
} }
void void kbd_release_key(struct kbd *kb, uint32_t time) {
kbd_release_key(struct kbd *kb, uint32_t time) {
kbd_unpress_key(kb, time); kbd_unpress_key(kb, time);
if (kb->print_intersect && kb->last_swipe) { if (kb->print_intersect && kb->last_swipe) {
printf("\n"); printf("\n");
@ -319,8 +311,7 @@ kbd_release_key(struct kbd *kb, uint32_t time) {
drwsurf_flip(kb->popup_surf); drwsurf_flip(kb->popup_surf);
} }
void void kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
// Output intersecting keys // Output intersecting keys
// (for external 'swiping'-based accelerators). // (for external 'swiping'-based accelerators).
if (kb->print_intersect) { if (kb->print_intersect) {
@ -331,8 +322,8 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
} }
struct key *intersect_key; struct key *intersect_key;
intersect_key = kbd_get_key(kb, x, y); intersect_key = kbd_get_key(kb, x, y);
if (intersect_key && if (intersect_key && (!kb->last_swipe ||
(!kb->last_swipe || intersect_key->label != kb->last_swipe->label)) { intersect_key->label != kb->last_swipe->label)) {
kbd_print_key_stdout(kb, intersect_key); kbd_print_key_stdout(kb, intersect_key);
kb->last_swipe = intersect_key; kb->last_swipe = intersect_key;
kbd_draw_key(kb, kb->last_swipe, Swipe); kbd_draw_key(kb, kb->last_swipe, Swipe);
@ -347,8 +338,7 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
drwsurf_flip(kb->popup_surf); drwsurf_flip(kb->popup_surf);
} }
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) || if ((k->type == NextLayer) || (k->type == BackLayer) ||
((k->type == Code) && (k->code == KEY_SPACE))) { ((k->type == Code) && (k->code == KEY_SPACE))) {
@ -361,7 +351,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
kb->compose++; kb->compose++;
if (kb->debug) if (kb->debug)
fprintf(stderr, "showing compose %d\n", kb->compose); fprintf(stderr, "showing compose %d\n", kb->compose);
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));
return; return;
} else { } else {
return; return;
@ -372,10 +363,11 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
case Code: case Code:
if (k->code_mod) { if (k->code_mod) {
if (k->reset_mod) { if (k->reset_mod) {
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, k->code_mod, 0, 0, 0); zwp_virtual_keyboard_v1_modifiers(kb->vkbd, k->code_mod, 0, 0,
0);
} else { } else {
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods ^ k->code_mod, 0, zwp_virtual_keyboard_v1_modifiers(
0, 0); kb->vkbd, kb->mods ^ k->code_mod, 0, 0, 0);
} }
} else { } else {
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0); zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
@ -415,7 +407,8 @@ 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]];
@ -424,7 +417,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
} }
break; break;
case Compose: case Compose:
// switch to the associated layout determined by the *next* keypress // switch to the associated layout determined by the *next*
// keypress
if (kb->compose == 0) { if (kb->compose == 0) {
kb->compose = 1; kb->compose = 1;
} else { } else {
@ -436,8 +430,8 @@ 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 case NextLayer: //(also handles previous layer when shift modifier is
//"first layer" with other modifiers) // 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
@ -445,7 +439,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
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]];
@ -460,7 +455,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
kbd_draw_key(kb, k, Press); kbd_draw_key(kb, k, Press);
if (kb->debug) if (kb->debug)
fprintf(stderr, "pressing copy key\n"); fprintf(stderr, "pressing copy key\n");
create_and_upload_keymap(kb, kb->layout->keymap_name, k->code, k->code_mod); create_and_upload_keymap(kb, kb->layout->keymap_name, k->code,
k->code_mod);
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0); zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
WL_KEYBOARD_KEY_STATE_PRESSED); WL_KEYBOARD_KEY_STATE_PRESSED);
@ -475,8 +471,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
drwsurf_flip(kb->popup_surf); drwsurf_flip(kb->popup_surf);
} }
void void kbd_print_key_stdout(struct kbd *kb, struct key *k) {
kbd_print_key_stdout(struct kbd *kb, struct key *k) {
/* printed keys may slightly differ from the actual output /* printed keys may slightly differ from the actual output
* we generally print what is on the key LABEL and only support the normal * we generally print what is on the key LABEL and only support the normal
* and shift layers. Other modifiers produce no output (Ctrl,Alt) * and shift layers. Other modifiers produce no output (Ctrl,Alt)
@ -514,33 +509,34 @@ kbd_print_key_stdout(struct kbd *kb, struct key *k) {
fflush(stdout); fflush(stdout);
} }
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, drw_do_clear(kb->popup_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, wl_surface_damage(kb->popup_surf->surf, kb->last_popup_x,
kb->last_popup_w, kb->last_popup_h); 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;
} }
} }
void void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
const char *label = (kb->mods & Shift) ? k->shift_label : k->label; const char *label = (kb->mods & Shift) ? k->shift_label : k->label;
if (kb->debug) if (kb->debug)
fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h, fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h,
label); label);
struct clr_scheme *scheme = (k->scheme == 0) ? &(kb->scheme) : &(kb->scheme1); struct clr_scheme *scheme =
(k->scheme == 0) ? &(kb->scheme) : &(kb->scheme1);
switch (type) { switch (type) {
case None: case None:
case Unpress: case Unpress:
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, scheme->fg); draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
scheme->fg);
break; break;
case Press: case Press:
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, draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
@ -548,8 +544,8 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
break; break;
} }
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
label); 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) {
@ -560,18 +556,18 @@ 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, drw_fill_rectangle(kb->popup_surf, kb->scheme.bg, k->x,
k->w, k->h); kb->last_popup_y, k->w, k->h);
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h, draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
KBD_KEY_BORDER, scheme->high); KBD_KEY_BORDER, scheme->high);
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y, k->w, drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
k->h, KBD_KEY_BORDER, label); 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);
} }
} }
void void kbd_draw_layout(struct kbd *kb) {
kbd_draw_layout(struct kbd *kb) {
struct drwsurf *d = kb->surf; struct drwsurf *d = kb->surf;
struct key *next_key = kb->layout->keys; struct key *next_key = kb->layout->keys;
if (kb->debug) if (kb->debug)
@ -595,8 +591,7 @@ kbd_draw_layout(struct kbd *kb) {
wl_surface_damage(d->surf, 0, 0, kb->w, kb->h); wl_surface_damage(d->surf, 0, 0, kb->w, kb->h);
} }
void void kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
fprintf(stderr, "Resize %dx%d %f, %d layouts\n", kb->w, kb->h, kb->scale, fprintf(stderr, "Resize %dx%d %f, %d layouts\n", kb->w, kb->h, kb->scale,
layoutcount); layoutcount);
@ -605,32 +600,30 @@ kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
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, fprintf(stderr, "Initialising layout %s, keymap %s\n",
layouts[i].keymap_name); layouts[i].name, layouts[i].keymap_name);
else else
fprintf(stderr, "Initialising unnamed layout %d, keymap %s\n", i, fprintf(stderr, "Initialising unnamed layout %d, keymap %s\n",
layouts[i].keymap_name); i, layouts[i].keymap_name);
} }
kbd_init_layout(&layouts[i], kb->w, kb->h); kbd_init_layout(&layouts[i], kb->w, kb->h);
} }
kbd_draw_layout(kb); kbd_draw_layout(kb);
} }
void void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
uint32_t height, uint32_t border, Color color) { uint32_t height, uint32_t border, Color color) {
drw_fill_rectangle(ds, color, x + border, y + border, width - (border * 2), drw_fill_rectangle(ds, color, x + border, y + border, width - (border * 2),
height - (border * 2)); height - (border * 2));
} }
void void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
uint32_t height, uint32_t border, Color color) { uint32_t height, uint32_t border, Color color) {
drw_over_rectangle(ds, color, x + border, y + border, width - (border * 2), drw_over_rectangle(ds, color, x + border, y + border, width - (border * 2),
height - (border * 2)); height - (border * 2));
} }
void void create_and_upload_keymap(struct kbd *kb, const char *name,
create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr, uint32_t comp_unichr,
uint32_t comp_shift_unichr) { uint32_t comp_shift_unichr) {
int keymap_index = -1; int keymap_index = -1;
for (int i = 0; i < NUMKEYMAPS; i++) { for (int i = 0; i < NUMKEYMAPS; i++) {
@ -651,8 +644,8 @@ create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr,
if (keymap_fd < 0) { if (keymap_fd < 0) {
die("could not create keymap fd\n"); die("could not create keymap fd\n");
} }
void *ptr = void *ptr = mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED,
mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, keymap_fd, 0); keymap_fd, 0);
if (ptr == (void *)-1) { if (ptr == (void *)-1) {
die("could not map keymap data\n"); die("could not map keymap data\n");
} }

203
main.c
View File

@ -1,22 +1,22 @@
#include "proto/fractional-scale-v1-client-protocol.h"
#include "proto/viewporter-client-protocol.h"
#include "proto/virtual-keyboard-unstable-v1-client-protocol.h" #include "proto/virtual-keyboard-unstable-v1-client-protocol.h"
#include "proto/wlr-layer-shell-unstable-v1-client-protocol.h" #include "proto/wlr-layer-shell-unstable-v1-client-protocol.h"
#include "proto/xdg-shell-client-protocol.h" #include "proto/xdg-shell-client-protocol.h"
#include "proto/fractional-scale-v1-client-protocol.h"
#include "proto/viewporter-client-protocol.h"
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include <poll.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/signalfd.h> #include <sys/signalfd.h>
#include <poll.h>
#include <unistd.h> #include <unistd.h>
#include <wayland-client-protocol.h> #include <wayland-client-protocol.h>
#include <wayland-client.h> #include <wayland-client.h>
#include <wchar.h> #include <wchar.h>
#include "keyboard.h"
#include "config.h" #include "config.h"
#include "keyboard.h"
/* lazy die macro */ /* lazy die macro */
#define die(...) \ #define die(...) \
@ -165,8 +165,7 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
char * char *estrdup(const char *s) {
estrdup(const char *s) {
char *p; char *p;
if (!(p = strdup(s))) { if (!(p = strdup(s))) {
@ -177,8 +176,7 @@ estrdup(const char *s) {
return p; return p;
} }
void void wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
uint32_t time, struct wl_surface *surface, int32_t id, uint32_t time, struct wl_surface *surface, int32_t id,
wl_fixed_t x, wl_fixed_t y) { wl_fixed_t x, wl_fixed_t y) {
struct key *next_key; struct key *next_key;
@ -194,18 +192,17 @@ wl_touch_down(void *data, struct wl_touch *wl_touch, 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_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,
wl_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,
uint32_t time, int32_t id) { uint32_t time, int32_t id) {
kbd_release_key(&keyboard, time); kbd_release_key(&keyboard, time);
} }
void void wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
int32_t id, wl_fixed_t x, wl_fixed_t y) { int32_t id, wl_fixed_t x, wl_fixed_t y) {
uint32_t touch_x, touch_y; uint32_t touch_x, touch_y;
@ -215,33 +212,26 @@ wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
kbd_motion_key(&keyboard, time, touch_x, touch_y); kbd_motion_key(&keyboard, time, touch_x, touch_y);
} }
void void wl_touch_frame(void *data, struct wl_touch *wl_touch) {}
wl_touch_frame(void *data, struct wl_touch *wl_touch) {}
void void wl_touch_cancel(void *data, struct wl_touch *wl_touch) {}
wl_touch_cancel(void *data, struct wl_touch *wl_touch) {}
void void wl_touch_shape(void *data, struct wl_touch *wl_touch, int32_t id,
wl_touch_shape(void *data, struct wl_touch *wl_touch, int32_t id,
wl_fixed_t major, wl_fixed_t minor) {} wl_fixed_t major, wl_fixed_t minor) {}
void void wl_touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id,
wl_touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id,
wl_fixed_t orientation) {} wl_fixed_t orientation) {}
void void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t serial, struct wl_surface *surface,
struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_x, wl_fixed_t surface_y) {}
wl_fixed_t surface_y) {}
void void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t serial, struct wl_surface *surface) {
struct wl_surface *surface) {
cur_x = cur_y = -1; cur_x = cur_y = -1;
} }
void void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
wl_fixed_t surface_x, wl_fixed_t surface_y) { wl_fixed_t surface_x, wl_fixed_t surface_y) {
cur_x = wl_fixed_to_int(surface_x); cur_x = wl_fixed_to_int(surface_x);
cur_y = wl_fixed_to_int(surface_y); cur_y = wl_fixed_to_int(surface_y);
@ -251,9 +241,9 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
} }
} }
void void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t serial, uint32_t time, uint32_t button,
uint32_t time, uint32_t button, uint32_t state) { uint32_t state) {
struct key *next_key; struct key *next_key;
cur_press = state == WL_POINTER_BUTTON_STATE_PRESSED; cur_press = state == WL_POINTER_BUTTON_STATE_PRESSED;
@ -275,15 +265,13 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
} }
} }
void void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time,
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, 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);
} }
void void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
enum wl_seat_capability caps) { enum wl_seat_capability caps) {
if ((caps & WL_SEAT_CAPABILITY_POINTER)) { if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
if (pointer == NULL) { if (pointer == NULL) {
@ -309,11 +297,9 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
} }
} }
void void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) {}
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) {
@ -325,10 +311,11 @@ wl_surface_enter(void *data, struct wl_surface *wl_surface,
resize(); resize();
} }
static void static void display_handle_geometry(void *data, struct wl_output *wl_output,
display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y, int x, int y, int physical_width,
int physical_width, int physical_height, int subpixel, int physical_height, int subpixel,
const char *make, const char *model, int transform) { const char *make, const char *model,
int transform) {
struct Output *output = data; struct Output *output = data;
// Swap width and height on rotated displays // Swap width and height on rotated displays
@ -346,11 +333,10 @@ display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
}; };
} }
static void static void display_handle_done(void *data, struct wl_output *wl_output) {}
display_handle_done(void *data, struct wl_output *wl_output) {}
static void static void display_handle_scale(void *data, struct wl_output *wl_output,
display_handle_scale(void *data, struct wl_output *wl_output, int32_t scale) { int32_t scale) {
struct Output *output = data; struct Output *output = data;
output->scale = scale; output->scale = scale;
@ -359,9 +345,9 @@ display_handle_scale(void *data, struct wl_output *wl_output, int32_t scale) {
}; };
} }
static void static void display_handle_mode(void *data, struct wl_output *wl_output,
display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags, uint32_t flags, int width, int height,
int width, int height, int refresh) {} int refresh) {}
static const struct wl_output_listener output_listener = { static const struct wl_output_listener output_listener = {
.geometry = display_handle_geometry, .geometry = display_handle_geometry,
@ -369,8 +355,8 @@ static const struct wl_output_listener output_listener = {
.done = display_handle_done, .done = display_handle_done,
.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,
xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial) { uint32_t serial) {
xdg_wm_base_pong(xdg_wm_base, serial); xdg_wm_base_pong(xdg_wm_base, serial);
} }
@ -378,17 +364,18 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = {
.ping = xdg_wm_base_ping, .ping = xdg_wm_base_ping,
}; };
void void handle_global(void *data, struct wl_registry *registry, uint32_t name,
handle_global(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) { const char *interface, uint32_t version) {
if (strcmp(interface, wl_compositor_interface.name) == 0) { if (strcmp(interface, wl_compositor_interface.name) == 0) {
compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 3); compositor =
wl_registry_bind(registry, name, &wl_compositor_interface, 3);
} 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;
output->scale = 1; output->scale = 1;
wl_output_add_listener(output->data, &output_listener, output); wl_output_add_listener(output->data, &output_listener, output);
@ -403,21 +390,22 @@ handle_global(void *data, struct wl_registry *registry, uint32_t name,
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); wm_base = 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) == } else if (strcmp(interface,
0) { wp_fractional_scale_manager_v1_interface.name) == 0) {
wfs_mgr = wl_registry_bind(registry, name, wfs_mgr = wl_registry_bind(
&wp_fractional_scale_manager_v1_interface, 1); 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 = wl_registry_bind(registry, name, &wp_viewporter_interface, 1); viewporter =
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(
&zwp_virtual_keyboard_manager_v1_interface, 1); registry, name, &zwp_virtual_keyboard_manager_v1_interface, 1);
} }
} }
void void handle_global_remove(void *data, struct wl_registry *registry,
handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { 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);
@ -430,8 +418,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);
@ -441,24 +429,22 @@ 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, struct xdg_popup *xdg_popup,
xdg_popup_configure(void *data, struct xdg_popup *xdg_popup, int32_t x, int32_t x, int32_t y, int32_t width,
int32_t y, int32_t width, int32_t height) { 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,
.popup_done = xdg_popup_done, .popup_done = xdg_popup_done,
}; };
static void static void wp_fractional_scale_prefered_scale(
wp_fractional_scale_prefered_scale(
void *data, 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;
@ -469,8 +455,7 @@ static const struct wp_fractional_scale_v1_listener
.preferred_scale = wp_fractional_scale_prefered_scale, .preferred_scale = wp_fractional_scale_prefered_scale,
}; };
void void resize() {
resize() {
keyboard.landscape = current_output->w > current_output->h; keyboard.landscape = current_output->w > current_output->h;
enum layout_id layer; enum layout_id layer;
@ -499,8 +484,7 @@ 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 || if (keyboard.w != w || keyboard.h != h ||
keyboard.scale != keyboard.pending_scale) { keyboard.scale != keyboard.pending_scale) {
@ -510,7 +494,8 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
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_draw_surf =
wp_fractional_scale_manager_v1_get_fractional_scale(
wfs_mgr, draw_surf.surf); wfs_mgr, draw_surf.surf);
wp_fractional_scale_v1_add_listener( wp_fractional_scale_v1_add_listener(
wfs_draw_surf, &wp_fractional_scale_listener, NULL); wfs_draw_surf, &wp_fractional_scale_listener, NULL);
@ -519,7 +504,8 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
draw_surf_viewport = draw_surf_viewport =
wp_viewporter_get_viewport(viewporter, draw_surf.surf); 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 {
wl_surface_set_buffer_scale(draw_surf.surf, keyboard.scale); wl_surface_set_buffer_scale(draw_surf.surf, keyboard.scale);
} }
@ -544,8 +530,8 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
xdg_wm_base_get_xdg_surface(wm_base, popup_draw_surf.surf); xdg_wm_base_get_xdg_surface(wm_base, popup_draw_surf.surf);
xdg_surface_add_listener(popup_xdg_surface, &xdg_popup_surface_listener, xdg_surface_add_listener(popup_xdg_surface, &xdg_popup_surface_listener,
NULL); NULL);
popup_xdg_popup = popup_xdg_popup = xdg_surface_get_popup(popup_xdg_surface, NULL,
xdg_surface_get_popup(popup_xdg_surface, NULL, popup_xdg_positioner); 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);
@ -564,15 +550,13 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
zwlr_layer_surface_v1_ack_configure(surface, serial); zwlr_layer_surface_v1_ack_configure(surface, serial);
} }
void void layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
zwlr_layer_surface_v1_destroy(surface); zwlr_layer_surface_v1_destroy(surface);
wl_surface_destroy(draw_surf.surf); wl_surface_destroy(draw_surf.surf);
run_display = false; run_display = false;
} }
void void usage(char *argv0) {
usage(char *argv0) {
fprintf(stderr, fprintf(stderr,
"usage: %s [-hov] [-H height] [-L landscape height] [-fn font] [-l " "usage: %s [-hov] [-H height] [-L landscape height] [-fn font] [-l "
"layers]\n", "layers]\n",
@ -605,13 +589,11 @@ usage(char *argv0) {
" --list-layers - Print the list of available layers\n"); " --list-layers - Print the list of available layers\n");
fprintf(stderr, fprintf(stderr,
" -l - Comma separated list of layers\n"); " -l - Comma separated list of layers\n");
fprintf( fprintf(stderr, " --landscape-layers - Comma separated list of "
stderr, "landscape layers\n");
" --landscape-layers - Comma separated list of landscape layers\n");
} }
void void list_layers() {
list_layers() {
int i; int i;
for (i = 0; i < NumLayouts - 1; i++) { for (i = 0; i < NumLayouts - 1; i++) {
if (layouts[i].name) { if (layouts[i].name) {
@ -620,8 +602,7 @@ list_layers() {
} }
} }
void void hide() {
hide() {
if (!layer_surface) { if (!layer_surface) {
return; return;
} }
@ -632,8 +613,7 @@ hide() {
hidden = true; hidden = true;
} }
void void show() {
show() {
if (layer_surface) { if (layer_surface) {
return; return;
} }
@ -656,21 +636,16 @@ show() {
hidden = false; hidden = false;
} }
void void toggle_visibility() {
toggle_visibility() {
if (hidden) if (hidden)
show(); show();
else else
hide(); hide();
} }
void void pipewarn() { fprintf(stderr, "wvkbd: cannot pipe data out.\n"); }
pipewarn() {
fprintf(stderr, "wvkbd: cannot pipe data out.\n");
}
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) {
@ -688,8 +663,7 @@ set_kbd_colors(uint8_t *bgra, char *hex) {
} }
} }
int int main(int argc, char **argv) {
main(int argc, char **argv) {
/* parse command line arguments */ /* parse command line arguments */
char *layer_names_list = NULL, *landscape_layer_names_list = NULL; char *layer_names_list = NULL, *landscape_layer_names_list = NULL;
const char *fc_font_pattern = NULL; const char *fc_font_pattern = NULL;
@ -748,7 +722,8 @@ main(int argc, char **argv) {
exit(1); exit(1);
} }
set_kbd_colors(keyboard.scheme.bg.bgra, argv[++i]); set_kbd_colors(keyboard.scheme.bg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-alpha")) || (!strcmp(argv[i], "--alpha"))) { } else if ((!strcmp(argv[i], "-alpha")) ||
(!strcmp(argv[i], "--alpha"))) {
if (i >= argc - 1) { if (i >= argc - 1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
@ -761,13 +736,15 @@ main(int argc, char **argv) {
exit(1); exit(1);
} }
set_kbd_colors(keyboard.scheme.fg.bgra, argv[++i]); set_kbd_colors(keyboard.scheme.fg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-fg-sp")) || (!strcmp(argv[i], "--fg-sp"))) { } else if ((!strcmp(argv[i], "-fg-sp")) ||
(!strcmp(argv[i], "--fg-sp"))) {
if (i >= argc - 1) { if (i >= argc - 1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
} }
set_kbd_colors(keyboard.scheme1.fg.bgra, argv[++i]); set_kbd_colors(keyboard.scheme1.fg.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-press")) || (!strcmp(argv[i], "--press"))) { } else if ((!strcmp(argv[i], "-press")) ||
(!strcmp(argv[i], "--press"))) {
if (i >= argc - 1) { if (i >= argc - 1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
@ -780,7 +757,8 @@ main(int argc, char **argv) {
exit(1); exit(1);
} }
set_kbd_colors(keyboard.scheme1.high.bgra, argv[++i]); set_kbd_colors(keyboard.scheme1.high.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-swipe")) || (!strcmp(argv[i], "--swipe"))) { } else if ((!strcmp(argv[i], "-swipe")) ||
(!strcmp(argv[i], "--swipe"))) {
if (i >= argc - 1) { if (i >= argc - 1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);
@ -793,7 +771,8 @@ main(int argc, char **argv) {
exit(1); exit(1);
} }
set_kbd_colors(keyboard.scheme1.swipe.bgra, argv[++i]); set_kbd_colors(keyboard.scheme1.swipe.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text")) || (!strcmp(argv[i], "--text"))) { } else if ((!strcmp(argv[i], "-text")) ||
(!strcmp(argv[i], "--text"))) {
if (i >= argc - 1) { if (i >= argc - 1) {
usage(argv[0]); usage(argv[0]);
exit(1); exit(1);

View File

@ -34,8 +34,7 @@
#include "os-compatibility.h" #include "os-compatibility.h"
int int os_fd_set_cloexec(int fd) {
os_fd_set_cloexec(int fd) {
long flags; long flags;
if (fd == -1) if (fd == -1)
@ -51,8 +50,7 @@ os_fd_set_cloexec(int fd) {
return 0; return 0;
} }
static int static int set_cloexec_or_close(int fd) {
set_cloexec_or_close(int fd) {
if (os_fd_set_cloexec(fd) != 0) { if (os_fd_set_cloexec(fd) != 0) {
close(fd); close(fd);
return -1; return -1;
@ -60,8 +58,7 @@ set_cloexec_or_close(int fd) {
return fd; return fd;
} }
int int os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
int ret; int ret;
#ifdef SOCK_CLOEXEC #ifdef SOCK_CLOEXEC
@ -85,8 +82,7 @@ os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
return -1; return -1;
} }
int int os_epoll_create_cloexec(void) {
os_epoll_create_cloexec(void) {
int fd; int fd;
#ifdef EPOLL_CLOEXEC #ifdef EPOLL_CLOEXEC
@ -101,8 +97,7 @@ os_epoll_create_cloexec(void) {
return set_cloexec_or_close(fd); return set_cloexec_or_close(fd);
} }
static int static int create_tmpfile_cloexec(char *tmpname) {
create_tmpfile_cloexec(char *tmpname) {
int fd; int fd;
#ifdef HAVE_MKOSTEMP #ifdef HAVE_MKOSTEMP
@ -141,8 +136,7 @@ create_tmpfile_cloexec(char *tmpname) {
* If posix_fallocate() is not supported, program may receive * If posix_fallocate() is not supported, program may receive
* SIGBUS on accessing mmap()'ed file contents instead. * SIGBUS on accessing mmap()'ed file contents instead.
*/ */
int int os_create_anonymous_file(off_t size) {
os_create_anonymous_file(off_t size) {
static const char template[] = "/weston-shared-XXXXXX"; static const char template[] = "/weston-shared-XXXXXX";
const char *path; const char *path;
char *name; char *name;
@ -192,8 +186,7 @@ os_create_anonymous_file(off_t size) {
} }
#ifndef MISSING_STRCHRNUL #ifndef MISSING_STRCHRNUL
char * char *strchrnul(const char *s, int c) {
strchrnul(const char *s, int c) {
while (*s && *s != c) while (*s && *s != c)
s++; s++;
return (char *)s; return (char *)s;

View File

@ -5,8 +5,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
static void static void randname(char *buf) {
randname(char *buf) {
struct timespec ts; struct timespec ts;
long r; long r;
clock_gettime(CLOCK_REALTIME, &ts); clock_gettime(CLOCK_REALTIME, &ts);
@ -17,8 +16,7 @@ randname(char *buf) {
} }
} }
static int static int create_shm_file(void) {
create_shm_file(void) {
int retries = 100; int retries = 100;
int fd; int fd;
do { do {
@ -34,8 +32,7 @@ create_shm_file(void) {
return -1; return -1;
} }
int int allocate_shm_file(size_t size) {
allocate_shm_file(size_t size) {
int fd = create_shm_file(); int fd = create_shm_file();
int ret; int ret;
if (fd < 0) if (fd < 0)