Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchdzugan committed Oct 29, 2024
1 parent b67d858 commit 137bb71
Show file tree
Hide file tree
Showing 12 changed files with 5 additions and 923 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.o
zkg
tags
/.vscode
2 changes: 0 additions & 2 deletions Sourcedeps
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ parse.o: parse.c helpers.h locales.h parse.h zkg.h types.h
OBJ += parse.o
zkg.o: zkg.c grab.h helpers.h parse.h zkg.h types.h
OBJ += zkg.o
types.o: types.c grab.h helpers.h parse.h zkg.h types.h
OBJ += types.o
64 changes: 0 additions & 64 deletions src/grab.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,78 +30,14 @@
void grab(void)
{
PUTS("grab");
/*
for (hotkey_t *hk = hotkeys_head; hk != NULL; hk = hk->next)
grab_chord(hk->chain->head);
*/
xcb_grab_keyboard(dpy, false, root, XCB_CURRENT_TIME, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
xcb_flush(dpy);
grabbed = true;
}

void grab_chord(chord_t *chord)
{
for (chord_t *c = chord; c != NULL; c = c->more) {
if (c->button == XCB_NONE) {
xcb_keycode_t *keycodes = keycodes_from_keysym(c->keysym);
if (keycodes != NULL)
for (xcb_keycode_t *kc = keycodes; *kc != XCB_NO_SYMBOL; kc++)
if (c->keysym == xcb_key_symbols_get_keysym(symbols, *kc, 0))
grab_key_button(*kc, c->button, c->modfield);
free(keycodes);
} else {
grab_key_button(XCB_NONE, c->button, c->modfield);
}
}
}

void grab_key_button(xcb_keycode_t keycode, xcb_button_t button, uint16_t modfield)
{
grab_key_button_checked(keycode, button, modfield);
if (modfield == XCB_MOD_MASK_ANY)
return;
if (num_lock != 0)
grab_key_button_checked(keycode, button, modfield | num_lock);
if (caps_lock != 0)
grab_key_button_checked(keycode, button, modfield | caps_lock);
if (scroll_lock != 0)
grab_key_button_checked(keycode, button, modfield | scroll_lock);
if (num_lock != 0 && caps_lock != 0)
grab_key_button_checked(keycode, button, modfield | num_lock | caps_lock);
if (caps_lock != 0 && scroll_lock != 0)
grab_key_button_checked(keycode, button, modfield | caps_lock | scroll_lock);
if (num_lock != 0 && scroll_lock != 0)
grab_key_button_checked(keycode, button, modfield | num_lock | scroll_lock);
if (num_lock != 0 && caps_lock != 0 && scroll_lock != 0)
grab_key_button_checked(keycode, button, modfield | num_lock | caps_lock | scroll_lock);
}

void grab_key_button_checked(xcb_keycode_t keycode, xcb_button_t button, uint16_t modfield)
{
xcb_generic_error_t *err;
if (button == XCB_NONE)
err = xcb_request_check(dpy, xcb_grab_key_checked(dpy, true, root, modfield, keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC));
else
err = xcb_request_check(dpy, xcb_grab_button_checked(dpy, true, root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, button, modfield));
unsigned int value = (button == XCB_NONE ? keycode : button);
char *type = (button == XCB_NONE ? "key" : "button");
if (err != NULL) {
warn("Could not grab %s %u with modfield %u: ", type, value, modfield);
if (err->error_code == XCB_ACCESS)
warn("the combination is already grabbed.\n");
else
warn("error %u encountered.\n", err->error_code);
free(err);
} else {
PRINTF("grab %s %u %u\n", type, value, modfield);
}
}

void ungrab(void)
{
PUTS("ungrab");
// xcb_ungrab_key(dpy, XCB_GRAB_ANY, root, XCB_BUTTON_MASK_ANY);
// xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_ANY, root, XCB_MOD_MASK_ANY);
xcb_ungrab_keyboard(dpy, XCB_CURRENT_TIME);
xcb_flush(dpy);
grabbed = false;
Expand Down
3 changes: 0 additions & 3 deletions src/grab.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include "zkg.h"

void grab(void);
void grab_chord(chord_t *chord);
void grab_key_button(xcb_keycode_t keycode, xcb_button_t button, uint16_t modfield);
void grab_key_button_checked(xcb_keycode_t keycode, xcb_button_t button, uint16_t modfield);
void ungrab(void);

#endif
57 changes: 0 additions & 57 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,60 +49,3 @@ void err(char *fmt, ...)
va_end(ap);
exit(EXIT_FAILURE);
}

void run(char *command, bool sync)
{
char *cmd[] = {shell, "-c", command, NULL};
spawn(cmd, sync);
}

void spawn(char *cmd[], bool sync)
{
if (fork() == 0) {
if (dpy != NULL)
close(xcb_get_file_descriptor(dpy));
if (sync) {
execute(cmd);
} else {
if (fork() == 0) {
execute(cmd);
}
exit(EXIT_SUCCESS);
}
}
wait(NULL);
}

void execute(char *cmd[])
{
setsid();
if (redir_fd != -1) {
dup2(redir_fd, STDOUT_FILENO);
dup2(redir_fd, STDERR_FILENO);
}
execvp(cmd[0], cmd);
err("Spawning failed.\n");
}

char *lgraph(char *s)
{
size_t len = strlen(s);
unsigned int i = 0;
while (i < len && !isgraph(s[i]))
i++;
if (i < len)
return (s + i);
else
return NULL;
}

char *rgraph(char *s)
{
int i = strlen(s) - 1;
while (i >= 0 && !isgraph(s[i]))
i--;
if (i >= 0)
return (s + i);
else
return NULL;
}
5 changes: 0 additions & 5 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,5 @@
void warn(char *fmt, ...);
__attribute__((noreturn))
void err(char *fmt, ...);
void execute(char *cmd[]);
void spawn(char *cmd[], bool sync);
void run(char *command, bool sync);
char *lgraph(char *s);
char *rgraph(char *s);

#endif
Loading

0 comments on commit 137bb71

Please sign in to comment.