mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-03-12 18:32:48 +01:00
Break on function definitions
This commit is contained in:
parent
1a36f6d5f2
commit
a152fd036f
@ -1,2 +1,4 @@
|
|||||||
BasedOnStyle: LLVM
|
BasedOnStyle: LLVM
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: All
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
41
drw.c
41
drw.c
@ -5,7 +5,9 @@
|
|||||||
#include "drw.h"
|
#include "drw.h"
|
||||||
#include "shm_open.h"
|
#include "shm_open.h"
|
||||||
|
|
||||||
void drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
|
void
|
||||||
|
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);
|
||||||
@ -19,13 +21,17 @@ void drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, double s) {
|
|||||||
setup_buffer(ds);
|
setup_buffer(ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drwsurf_flip(struct drwsurf *ds) {
|
void
|
||||||
|
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 drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void
|
||||||
uint32_t w, uint32_t h, uint32_t b, const char *label) {
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
cairo_save(d->cairo);
|
cairo_save(d->cairo);
|
||||||
|
|
||||||
@ -47,8 +53,9 @@ void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
|||||||
cairo_restore(d->cairo);
|
cairo_restore(d->cairo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
|
void
|
||||||
uint32_t h) {
|
drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w, 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);
|
||||||
@ -58,8 +65,10 @@ void drw_do_clear(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t w,
|
|||||||
cairo_restore(d->cairo);
|
cairo_restore(d->cairo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void
|
||||||
uint32_t w, uint32_t h, bool over) {
|
drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
|
uint32_t w, uint32_t h, bool over)
|
||||||
|
{
|
||||||
cairo_save(d->cairo);
|
cairo_save(d->cairo);
|
||||||
|
|
||||||
if (over) {
|
if (over) {
|
||||||
@ -77,17 +86,23 @@ void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
|||||||
cairo_restore(d->cairo);
|
cairo_restore(d->cairo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void
|
||||||
uint32_t w, uint32_t h) {
|
drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
|
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 drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
void
|
||||||
uint32_t w, uint32_t h) {
|
drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
|
||||||
|
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 setup_buffer(struct drwsurf *drwsurf) {
|
uint32_t
|
||||||
|
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;
|
||||||
|
|
||||||
|
93
keyboard.c
93
keyboard.c
@ -19,7 +19,9 @@
|
|||||||
#endif
|
#endif
|
||||||
#include KEYMAP
|
#include KEYMAP
|
||||||
|
|
||||||
void kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
|
void
|
||||||
|
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;
|
||||||
@ -40,7 +42,9 @@ void kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index) {
|
|||||||
kbd_draw_layout(kb);
|
kbd_draw_layout(kb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_next_layer(struct kbd *kb, struct key *k, bool invert) {
|
void
|
||||||
|
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)) {
|
||||||
@ -100,7 +104,9 @@ void 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 kbd_get_rows(struct layout *l) {
|
uint8_t
|
||||||
|
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) {
|
||||||
@ -112,7 +118,9 @@ uint8_t kbd_get_rows(struct layout *l) {
|
|||||||
return rows + 1;
|
return rows + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum layout_id *kbd_init_layers(char *layer_names_list) {
|
enum layout_id *
|
||||||
|
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;
|
||||||
@ -150,8 +158,10 @@ enum layout_id *kbd_init_layers(char *layer_names_list) {
|
|||||||
return layers;
|
return layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
|
void
|
||||||
char *landscape_layer_names_list) {
|
kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
|
||||||
|
char *landscape_layer_names_list)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf(stderr, "Initializing keyboard\n");
|
fprintf(stderr, "Initializing keyboard\n");
|
||||||
@ -191,7 +201,9 @@ void 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 kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
|
void
|
||||||
|
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);
|
||||||
|
|
||||||
@ -222,7 +234,9 @@ void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double kbd_get_row_length(struct key *k) {
|
double
|
||||||
|
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;
|
||||||
@ -231,7 +245,9 @@ double kbd_get_row_length(struct key *k) {
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
|
struct key *
|
||||||
|
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)
|
||||||
@ -247,7 +263,9 @@ struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t kbd_get_layer_index(struct kbd *kb, struct layout *l) {
|
size_t
|
||||||
|
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;
|
||||||
@ -256,7 +274,9 @@ size_t kbd_get_layer_index(struct kbd *kb, struct layout *l) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_unpress_key(struct kbd *kb, uint32_t time) {
|
void
|
||||||
|
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) {
|
||||||
@ -295,7 +315,9 @@ void kbd_unpress_key(struct kbd *kb, uint32_t time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_release_key(struct kbd *kb, uint32_t time) {
|
void
|
||||||
|
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");
|
||||||
@ -311,7 +333,9 @@ void kbd_release_key(struct kbd *kb, uint32_t time) {
|
|||||||
drwsurf_flip(kb->popup_surf);
|
drwsurf_flip(kb->popup_surf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
|
void
|
||||||
|
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) {
|
||||||
@ -338,7 +362,9 @@ void 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 kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
void
|
||||||
|
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))) {
|
||||||
@ -471,7 +497,9 @@ void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
drwsurf_flip(kb->popup_surf);
|
drwsurf_flip(kb->popup_surf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_print_key_stdout(struct kbd *kb, struct key *k) {
|
void
|
||||||
|
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)
|
||||||
@ -509,7 +537,9 @@ void kbd_print_key_stdout(struct kbd *kb, struct key *k) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_clear_last_popup(struct kbd *kb) {
|
void
|
||||||
|
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);
|
||||||
@ -520,7 +550,9 @@ void kbd_clear_last_popup(struct kbd *kb) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
|
void
|
||||||
|
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,
|
||||||
@ -567,7 +599,9 @@ void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kbd_draw_layout(struct kbd *kb) {
|
void
|
||||||
|
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)
|
||||||
@ -591,7 +625,9 @@ void 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 kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
|
void
|
||||||
|
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);
|
||||||
|
|
||||||
@ -611,20 +647,25 @@ void kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount) {
|
|||||||
kbd_draw_layout(kb);
|
kbd_draw_layout(kb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
void
|
||||||
uint32_t height, uint32_t border, Color color) {
|
draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
|
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 draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
void
|
||||||
uint32_t height, uint32_t border, Color color) {
|
draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||||
|
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 create_and_upload_keymap(struct kbd *kb, const char *name,
|
void
|
||||||
uint32_t comp_unichr,
|
create_and_upload_keymap(struct kbd *kb, const char *name, 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++) {
|
||||||
if (!strcmp(keymap_names[i], name)) {
|
if (!strcmp(keymap_names[i], name)) {
|
||||||
|
216
main.c
216
main.c
@ -165,7 +165,9 @@ 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 *estrdup(const char *s) {
|
char *
|
||||||
|
estrdup(const char *s)
|
||||||
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!(p = strdup(s))) {
|
if (!(p = strdup(s))) {
|
||||||
@ -176,9 +178,11 @@ char *estrdup(const char *s) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
|
void
|
||||||
uint32_t time, struct wl_surface *surface, int32_t id,
|
wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
|
||||||
wl_fixed_t x, wl_fixed_t y) {
|
uint32_t time, struct wl_surface *surface, int32_t id,
|
||||||
|
wl_fixed_t x, wl_fixed_t y)
|
||||||
|
{
|
||||||
struct key *next_key;
|
struct key *next_key;
|
||||||
uint32_t touch_x, touch_y;
|
uint32_t touch_x, touch_y;
|
||||||
|
|
||||||
@ -197,13 +201,17 @@ void wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,
|
void
|
||||||
uint32_t time, int32_t id) {
|
wl_touch_up(void *data, struct wl_touch *wl_touch, uint32_t serial,
|
||||||
|
uint32_t time, int32_t id)
|
||||||
|
{
|
||||||
kbd_release_key(&keyboard, time);
|
kbd_release_key(&keyboard, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
|
void
|
||||||
int32_t id, wl_fixed_t x, wl_fixed_t y) {
|
wl_touch_motion(void *data, struct wl_touch *wl_touch, uint32_t time,
|
||||||
|
int32_t id, wl_fixed_t x, wl_fixed_t y)
|
||||||
|
{
|
||||||
uint32_t touch_x, touch_y;
|
uint32_t touch_x, touch_y;
|
||||||
|
|
||||||
touch_x = wl_fixed_to_int(x);
|
touch_x = wl_fixed_to_int(x);
|
||||||
@ -212,27 +220,46 @@ void 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 wl_touch_frame(void *data, struct wl_touch *wl_touch) {}
|
void
|
||||||
|
wl_touch_frame(void *data, struct wl_touch *wl_touch)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_touch_cancel(void *data, struct wl_touch *wl_touch) {}
|
void
|
||||||
|
wl_touch_cancel(void *data, struct wl_touch *wl_touch)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_touch_shape(void *data, struct wl_touch *wl_touch, int32_t id,
|
void
|
||||||
wl_fixed_t major, wl_fixed_t minor) {}
|
wl_touch_shape(void *data, struct wl_touch *wl_touch, int32_t id,
|
||||||
|
wl_fixed_t major, wl_fixed_t minor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id,
|
void
|
||||||
wl_fixed_t orientation) {}
|
wl_touch_orientation(void *data, struct wl_touch *wl_touch, int32_t id,
|
||||||
|
wl_fixed_t orientation)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
void
|
||||||
uint32_t serial, struct wl_surface *surface,
|
wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
||||||
wl_fixed_t surface_x, wl_fixed_t surface_y) {}
|
struct wl_surface *surface, wl_fixed_t surface_x,
|
||||||
|
wl_fixed_t surface_y)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
|
void
|
||||||
uint32_t serial, struct wl_surface *surface) {
|
wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
||||||
|
struct wl_surface *surface)
|
||||||
|
{
|
||||||
cur_x = cur_y = -1;
|
cur_x = cur_y = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
void
|
||||||
wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
||||||
|
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);
|
||||||
|
|
||||||
@ -241,9 +268,10 @@ void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
void
|
||||||
uint32_t serial, uint32_t time, uint32_t button,
|
wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
||||||
uint32_t state) {
|
uint32_t time, uint32_t button, 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;
|
||||||
|
|
||||||
@ -265,14 +293,18 @@ void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
void
|
||||||
uint32_t axis, wl_fixed_t value) {
|
wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time,
|
||||||
|
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 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
void
|
||||||
enum wl_seat_capability caps) {
|
seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
||||||
|
enum wl_seat_capability caps)
|
||||||
|
{
|
||||||
if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
|
if ((caps & WL_SEAT_CAPABILITY_POINTER)) {
|
||||||
if (pointer == NULL) {
|
if (pointer == NULL) {
|
||||||
pointer = wl_seat_get_pointer(wl_seat);
|
pointer = wl_seat_get_pointer(wl_seat);
|
||||||
@ -297,10 +329,15 @@ void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) {}
|
void
|
||||||
|
seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void wl_surface_enter(void *data, struct wl_surface *wl_surface,
|
void
|
||||||
struct wl_output *wl_output) {
|
wl_surface_enter(void *data, struct wl_surface *wl_surface,
|
||||||
|
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];
|
||||||
@ -311,11 +348,11 @@ void wl_surface_enter(void *data, struct wl_surface *wl_surface,
|
|||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_handle_geometry(void *data, struct wl_output *wl_output,
|
static void
|
||||||
int x, int y, int physical_width,
|
display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
|
||||||
int physical_height, int subpixel,
|
int physical_width, int physical_height, int subpixel,
|
||||||
const char *make, const char *model,
|
const char *make, const char *model, int transform)
|
||||||
int transform) {
|
{
|
||||||
struct Output *output = data;
|
struct Output *output = data;
|
||||||
|
|
||||||
// Swap width and height on rotated displays
|
// Swap width and height on rotated displays
|
||||||
@ -333,10 +370,14 @@ static void display_handle_geometry(void *data, struct wl_output *wl_output,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_handle_done(void *data, struct wl_output *wl_output) {}
|
static void
|
||||||
|
display_handle_done(void *data, struct wl_output *wl_output)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static void display_handle_scale(void *data, struct wl_output *wl_output,
|
static void
|
||||||
int32_t scale) {
|
display_handle_scale(void *data, struct wl_output *wl_output, int32_t scale)
|
||||||
|
{
|
||||||
struct Output *output = data;
|
struct Output *output = data;
|
||||||
output->scale = scale;
|
output->scale = scale;
|
||||||
|
|
||||||
@ -345,9 +386,11 @@ static void display_handle_scale(void *data, struct wl_output *wl_output,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_handle_mode(void *data, struct wl_output *wl_output,
|
static void
|
||||||
uint32_t flags, int width, int height,
|
display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
|
||||||
int refresh) {}
|
int width, int height, 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,
|
||||||
@ -355,8 +398,9 @@ 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 xdg_wm_base_ping(void *data, struct xdg_wm_base *xdg_wm_base,
|
static void
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,8 +408,10 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
|||||||
.ping = xdg_wm_base_ping,
|
.ping = xdg_wm_base_ping,
|
||||||
};
|
};
|
||||||
|
|
||||||
void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
void
|
||||||
const char *interface, uint32_t version) {
|
handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||||
|
const char *interface, uint32_t version)
|
||||||
|
{
|
||||||
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
compositor =
|
compositor =
|
||||||
wl_registry_bind(registry, name, &wl_compositor_interface, 3);
|
wl_registry_bind(registry, name, &wl_compositor_interface, 3);
|
||||||
@ -404,8 +450,9 @@ void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_global_remove(void *data, struct wl_registry *registry,
|
void
|
||||||
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);
|
||||||
@ -418,9 +465,10 @@ void handle_global_remove(void *data, struct wl_registry *registry,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xdg_popup_surface_configure(void *data,
|
static void
|
||||||
struct xdg_surface *xdg_surface,
|
xdg_popup_surface_configure(void *data, 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);
|
||||||
}
|
}
|
||||||
@ -429,24 +477,30 @@ static const struct xdg_surface_listener xdg_popup_surface_listener = {
|
|||||||
.configure = xdg_popup_surface_configure,
|
.configure = xdg_popup_surface_configure,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void xdg_popup_configure(void *data, struct xdg_popup *xdg_popup,
|
static void
|
||||||
int32_t x, int32_t y, int32_t width,
|
xdg_popup_configure(void *data, struct xdg_popup *xdg_popup, int32_t x,
|
||||||
int32_t height) {
|
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 xdg_popup_done(void *data, struct xdg_popup *xdg_popup) {}
|
static void
|
||||||
|
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 wp_fractional_scale_prefered_scale(
|
static void
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,7 +509,9 @@ static const struct wp_fractional_scale_v1_listener
|
|||||||
.preferred_scale = wp_fractional_scale_prefered_scale,
|
.preferred_scale = wp_fractional_scale_prefered_scale,
|
||||||
};
|
};
|
||||||
|
|
||||||
void resize() {
|
void
|
||||||
|
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;
|
||||||
@ -484,8 +540,10 @@ void resize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
|
void
|
||||||
uint32_t serial, uint32_t w, uint32_t h) {
|
layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
|
||||||
|
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) {
|
||||||
keyboard.w = w;
|
keyboard.w = w;
|
||||||
@ -550,13 +608,17 @@ void 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 layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
|
void
|
||||||
|
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 usage(char *argv0) {
|
void
|
||||||
|
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",
|
||||||
@ -593,7 +655,9 @@ void usage(char *argv0) {
|
|||||||
"landscape layers\n");
|
"landscape layers\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_layers() {
|
void
|
||||||
|
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) {
|
||||||
@ -602,7 +666,9 @@ void list_layers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide() {
|
void
|
||||||
|
hide()
|
||||||
|
{
|
||||||
if (!layer_surface) {
|
if (!layer_surface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -613,7 +679,9 @@ void hide() {
|
|||||||
hidden = true;
|
hidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void show() {
|
void
|
||||||
|
show()
|
||||||
|
{
|
||||||
if (layer_surface) {
|
if (layer_surface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -636,16 +704,24 @@ void show() {
|
|||||||
hidden = false;
|
hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggle_visibility() {
|
void
|
||||||
|
toggle_visibility()
|
||||||
|
{
|
||||||
if (hidden)
|
if (hidden)
|
||||||
show();
|
show();
|
||||||
else
|
else
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pipewarn() { fprintf(stderr, "wvkbd: cannot pipe data out.\n"); }
|
void
|
||||||
|
pipewarn()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "wvkbd: cannot pipe data out.\n");
|
||||||
|
}
|
||||||
|
|
||||||
void set_kbd_colors(uint8_t *bgra, char *hex) {
|
void
|
||||||
|
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) {
|
||||||
@ -663,7 +739,9 @@ void set_kbd_colors(uint8_t *bgra, char *hex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int
|
||||||
|
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;
|
||||||
|
@ -34,7 +34,9 @@
|
|||||||
|
|
||||||
#include "os-compatibility.h"
|
#include "os-compatibility.h"
|
||||||
|
|
||||||
int os_fd_set_cloexec(int fd) {
|
int
|
||||||
|
os_fd_set_cloexec(int fd)
|
||||||
|
{
|
||||||
long flags;
|
long flags;
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@ -50,7 +52,9 @@ int os_fd_set_cloexec(int fd) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_cloexec_or_close(int fd) {
|
static int
|
||||||
|
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;
|
||||||
@ -58,7 +62,9 @@ static int set_cloexec_or_close(int fd) {
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
|
int
|
||||||
|
os_socketpair_cloexec(int domain, int type, int protocol, int *sv)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
#ifdef SOCK_CLOEXEC
|
#ifdef SOCK_CLOEXEC
|
||||||
@ -82,7 +88,9 @@ int os_socketpair_cloexec(int domain, int type, int protocol, int *sv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int os_epoll_create_cloexec(void) {
|
int
|
||||||
|
os_epoll_create_cloexec(void)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef EPOLL_CLOEXEC
|
#ifdef EPOLL_CLOEXEC
|
||||||
@ -97,7 +105,9 @@ int os_epoll_create_cloexec(void) {
|
|||||||
return set_cloexec_or_close(fd);
|
return set_cloexec_or_close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_tmpfile_cloexec(char *tmpname) {
|
static int
|
||||||
|
create_tmpfile_cloexec(char *tmpname)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef HAVE_MKOSTEMP
|
#ifdef HAVE_MKOSTEMP
|
||||||
@ -136,7 +146,9 @@ static int 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 os_create_anonymous_file(off_t size) {
|
int
|
||||||
|
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;
|
||||||
@ -186,7 +198,9 @@ int os_create_anonymous_file(off_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MISSING_STRCHRNUL
|
#ifndef MISSING_STRCHRNUL
|
||||||
char *strchrnul(const char *s, int c) {
|
char *
|
||||||
|
strchrnul(const char *s, int c)
|
||||||
|
{
|
||||||
while (*s && *s != c)
|
while (*s && *s != c)
|
||||||
s++;
|
s++;
|
||||||
return (char *)s;
|
return (char *)s;
|
||||||
|
12
shm_open.c
12
shm_open.c
@ -5,7 +5,9 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static void randname(char *buf) {
|
static void
|
||||||
|
randname(char *buf)
|
||||||
|
{
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
long r;
|
long r;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
@ -16,7 +18,9 @@ static void randname(char *buf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_shm_file(void) {
|
static int
|
||||||
|
create_shm_file(void)
|
||||||
|
{
|
||||||
int retries = 100;
|
int retries = 100;
|
||||||
int fd;
|
int fd;
|
||||||
do {
|
do {
|
||||||
@ -32,7 +36,9 @@ static int create_shm_file(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int allocate_shm_file(size_t size) {
|
int
|
||||||
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user