cagebreak/keybinding.h
Jan Beich 9ad7c921d6
Unbreak build on FreeBSD (#37)
* Disable POSIX compliance when using reallocarray

cagebreak.c:197:11: warning: implicit declaration of function 'reallocarray' is invalid in C99 [-Wimplicit-function-declaration]
                        line = reallocarray(line, line_length, sizeof(char));
                               ^
cagebreak.c:197:9: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                        line = reallocarray(line, line_length, sizeof(char));
                             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ipc_server.c:248:25: warning: implicit declaration of function 'reallocarray' is invalid in C99 [-Wimplicit-function-declaration]
                client->read_buffer = reallocarray(client->read_buffer,
                                      ^
ipc_server.c:248:23: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
                client->read_buffer = reallocarray(client->read_buffer,
                                    ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* Promote -Wimplicit-function-declaration to -Werror

To help find bugs caused by _POSIX_C_SOURCE. Already errors in C++ and C23.

* Fix -Wstrict-prototypes, default in Clang >= 15

In file included from output.c:30:
keybinding.h:136:21: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
keybinding_list_init();
                    ^
                     void
output.c:335:20: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
empty_output_config() {
                   ^
                    void
In file included from seat.c:29:
input_manager.h:19:40: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
input_manager_create_empty_input_config();
                                       ^
                                        void
input_manager.c:92:40: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
input_manager_create_empty_input_config() {
                                       ^
                                        void
keybinding.c:129:21: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
keybinding_list_init() {
                    ^
                     void

See also
11da1b53d8
https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c/60521
2023-01-09 17:20:24 +01:00

144 lines
7.2 KiB
C

// Copyright 2020 - 2023, project-repo and the cagebreak contributors
// SPDX -License-Identifier: MIT
#ifndef KEYBINDING_H
#define KEYBINDING_H
#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <xkbcommon/xkbcommon.h>
struct cg_server;
#define FOREACH_KEYBINDING(KEYBINDING) \
KEYBINDING(KEYBINDING_RUN_COMMAND, \
exec) /* data.c is the string to execute */ \
KEYBINDING(KEYBINDING_CLOSE_VIEW, close) \
KEYBINDING(KEYBINDING_SPLIT_VERTICAL, vsplit) \
KEYBINDING(KEYBINDING_SPLIT_HORIZONTAL, hsplit) \
KEYBINDING(KEYBINDING_CHANGE_TTY, switchvt) /*data.u is the desired tty*/ \
KEYBINDING(KEYBINDING_LAYOUT_FULLSCREEN, only) \
KEYBINDING(KEYBINDING_CYCLE_VIEWS, \
cycle_views) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CYCLE_TILES, \
cycle_tiles) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CYCLE_OUTPUT, \
cycle_outputs) /* data.b is 0 if forward, 1 if reverse */ \
KEYBINDING(KEYBINDING_CONFIGURE_OUTPUT, \
output) /* data.o_cfg is the desired output */ \
\
KEYBINDING(KEYBINDING_CONFIGURE_MESSAGE, \
configure_message) /* data.m_cfg is the desired config */ \
KEYBINDING(KEYBINDING_CONFIGURE_INPUT, \
input) /* data.i_cfg is the desired input configuration */ \
\
KEYBINDING(KEYBINDING_QUIT, quit) \
KEYBINDING(KEYBINDING_NOOP, abort) \
KEYBINDING(KEYBINDING_SWITCH_OUTPUT, \
screen) /* data.u is the desired output */ \
KEYBINDING(KEYBINDING_SWITCH_WORKSPACE, \
workspace) /* data.u is the desired workspace */ \
KEYBINDING(KEYBINDING_SWITCH_MODE, mode) /* data.u is the desired mode */ \
KEYBINDING(KEYBINDING_SWITCH_DEFAULT_MODE, \
setmode) /* data.u is the desired mode */ \
KEYBINDING( \
KEYBINDING_RESIZE_TILE_HORIZONTAL, \
resize_tile_horizontal) /* data.i is the number of pixels to add */ \
\
KEYBINDING( \
KEYBINDING_RESIZE_TILE_VERTICAL, \
resize_tile_vertical) /* data.i is the number of pixels to add to */ \
\
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_WORKSPACE, \
movetoworkspace) /* data.u is the desired workspace */ \
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_OUTPUT, \
movetoscreen) /* data.u is the desired output */ \
KEYBINDING(KEYBINDING_MOVE_VIEW_TO_CYCLE_OUTPUT, \
move_view_to_cycle_output) /* data.b is 0 if forward, 1 if */ \
\
KEYBINDING(KEYBINDING_DUMP, dump) \
KEYBINDING(KEYBINDING_SHOW_TIME, time) \
KEYBINDING(KEYBINDING_SHOW_INFO, show_info) \
KEYBINDING(KEYBINDING_DISPLAY_MESSAGE, message) \
KEYBINDING(KEYBINDING_CURSOR, cursor) \
\
KEYBINDING(KEYBINDING_SWAP_LEFT, exchangeleft) \
KEYBINDING(KEYBINDING_SWAP_RIGHT, exchangeright) \
KEYBINDING(KEYBINDING_SWAP_TOP, exchangeup) \
KEYBINDING(KEYBINDING_SWAP_BOTTOM, exchangedown) \
\
KEYBINDING(KEYBINDING_FOCUS_LEFT, focusleft) \
KEYBINDING(KEYBINDING_FOCUS_RIGHT, focusright) \
KEYBINDING(KEYBINDING_FOCUS_TOP, focusup) \
KEYBINDING(KEYBINDING_FOCUS_BOTTOM, focusdown) \
KEYBINDING(KEYBINDING_FOCUS_TILE, focus_tile) \
\
KEYBINDING(KEYBINDING_DEFINEKEY, \
definekey) /* data.kb is the keybinding definition */ \
KEYBINDING(KEYBINDING_BACKGROUND, \
background) /* data.color is the background color */ \
KEYBINDING(KEYBINDING_DEFINEMODE, \
definemode) /* data.c is the mode name */ \
KEYBINDING(KEYBINDING_WORKSPACES, \
workspaces) /* data.i is the number of workspaces */
#define GENERATE_ENUM(ENUM, NAME) ENUM,
#define GENERATE_STRING(STRING, NAME) #NAME,
/* Important: if you add a keybinding which uses data.c or requires "free"
* to be called, don't forget to add it to the function "keybinding_list_free"
* in keybinding.c */
enum keybinding_action { FOREACH_KEYBINDING(GENERATE_ENUM) };
extern char *keybinding_action_string[];
union keybinding_params {
char *c;
uint32_t u;
int32_t i;
bool b;
float color[3];
struct keybinding *kb;
struct cg_output_config *o_cfg;
struct cg_input_config *i_cfg;
struct cg_message_config *m_cfg;
};
struct keybinding {
uint16_t mode;
xkb_mod_mask_t modifiers;
xkb_keysym_t key;
enum keybinding_action action;
union keybinding_params data; // See enum keybinding_action for details
};
struct keybinding_list {
uint32_t length;
uint32_t capacity;
struct keybinding **keybindings;
};
int
keybinding_list_push(struct keybinding_list *list,
struct keybinding *keybinding);
void
keybinding_list_free(struct keybinding_list *list);
void
keybinding_cycle_outputs(struct cg_server *server, bool reverse,
bool trigger_event);
struct keybinding **
find_keybinding(const struct keybinding_list *list,
const struct keybinding *keybinding);
struct keybinding_list *
keybinding_list_init(void);
int
run_action(enum keybinding_action action, struct cg_server *server,
union keybinding_params data);
void
keybinding_free(struct keybinding *keybinding, bool recursive);
#endif /* end of include guard KEYBINDINGS_H */