Move code to separate modules
This commit is contained in:
parent
2f735200f3
commit
875e8c9d4d
8 changed files with 45 additions and 42 deletions
1
Makefile
1
Makefile
|
@ -27,6 +27,7 @@ RUST_APIS = \
|
||||||
src/settings.h
|
src/settings.h
|
||||||
|
|
||||||
MODULES_SRC = \
|
MODULES_SRC = \
|
||||||
|
src/config/cursors.c \
|
||||||
src/config/keys.c \
|
src/config/keys.c \
|
||||||
src/config/buttons.c \
|
src/config/buttons.c \
|
||||||
src/config/layouts.c \
|
src/config/layouts.c \
|
||||||
|
|
21
src/config/cursors.c
Normal file
21
src/config/cursors.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "cursors.h"
|
||||||
|
|
||||||
|
#include <X11/cursorfont.h>
|
||||||
|
|
||||||
|
const Cursor cursors[CURSORS_COUNT] = { 0, 0, 0 };
|
||||||
|
|
||||||
|
void cursors_create(Display *const display)
|
||||||
|
{
|
||||||
|
Cursor *const cursors_ptr = (Cursor*)cursors;
|
||||||
|
cursors_ptr[CURSOR_NORMAL] = XCreateFontCursor(display, XC_left_ptr);
|
||||||
|
cursors_ptr[CURSOR_RESIZE] = XCreateFontCursor(display, XC_sizing);
|
||||||
|
cursors_ptr[CURSOR_MOVE] = XCreateFontCursor(display, XC_fleur);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cursors_destroy(Display *const display)
|
||||||
|
{
|
||||||
|
Cursor *const cursors_ptr = (Cursor*)cursors;
|
||||||
|
XFreeCursor(display, cursors_ptr[CURSOR_NORMAL]);
|
||||||
|
XFreeCursor(display, cursors_ptr[CURSOR_RESIZE]);
|
||||||
|
XFreeCursor(display, cursors_ptr[CURSOR_MOVE]);
|
||||||
|
}
|
17
src/config/cursors.h
Normal file
17
src/config/cursors.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef _CONFIG_CURSORS_H
|
||||||
|
#define _CONFIG_CURSORS_H
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
#define CURSOR_NORMAL 0
|
||||||
|
#define CURSOR_RESIZE 1
|
||||||
|
#define CURSOR_MOVE 2
|
||||||
|
|
||||||
|
#define CURSORS_COUNT 3
|
||||||
|
|
||||||
|
extern const Cursor cursors[CURSORS_COUNT];
|
||||||
|
|
||||||
|
void cursors_create(Display *display);
|
||||||
|
void cursors_destroy(Display *display);
|
||||||
|
|
||||||
|
#endif // _CONFIG_CURSORS_H
|
23
src/drw.c
23
src/drw.c
|
@ -65,26 +65,3 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
||||||
drw_clr_create(drw, &ret[i], clrnames[i]);
|
drw_clr_create(drw, &ret[i], clrnames[i]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cur *
|
|
||||||
drw_cur_create(Drw *drw, int shape)
|
|
||||||
{
|
|
||||||
Cur *cur;
|
|
||||||
|
|
||||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
|
||||||
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
drw_cur_free(Drw *drw, Cur *cursor)
|
|
||||||
{
|
|
||||||
if (!cursor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
XFreeCursor(drw->dpy, cursor->cursor);
|
|
||||||
free(cursor);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#ifndef _DRW_H
|
#ifndef _DRW_H
|
||||||
#define _DRW_H
|
#define _DRW_H
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Cursor cursor;
|
|
||||||
} Cur;
|
|
||||||
|
|
||||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||||
typedef XftColor Clr;
|
typedef XftColor Clr;
|
||||||
|
|
||||||
|
@ -25,8 +21,4 @@ void drw_free(Drw *drw);
|
||||||
/* Colorscheme abstraction */
|
/* Colorscheme abstraction */
|
||||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
||||||
|
|
||||||
/* Cursor abstraction */
|
|
||||||
Cur *drw_cur_create(Drw *drw, int shape);
|
|
||||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
|
||||||
|
|
||||||
#endif // _DRW_H
|
#endif // _DRW_H
|
||||||
|
|
12
src/dwm.c
12
src/dwm.c
|
@ -154,7 +154,6 @@ static Unit global_unit = NULL;
|
||||||
static const char broken[] = "broken";
|
static const char broken[] = "broken";
|
||||||
static unsigned int numlockmask = 0;
|
static unsigned int numlockmask = 0;
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
static Cur *cursor[CurLast];
|
|
||||||
static Clr **scheme;
|
static Clr **scheme;
|
||||||
static Drw *drw;
|
static Drw *drw;
|
||||||
static Monitor *mons, *selmon;
|
static Monitor *mons, *selmon;
|
||||||
|
@ -225,9 +224,7 @@ int dwm_main(const char *const new_program_title)
|
||||||
|
|
||||||
updategeom();
|
updategeom();
|
||||||
/* init cursors */
|
/* init cursors */
|
||||||
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
|
cursors_create(drw->dpy);
|
||||||
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
|
||||||
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
|
||||||
/* init appearance */
|
/* init appearance */
|
||||||
scheme_create();
|
scheme_create();
|
||||||
|
|
||||||
|
@ -252,7 +249,7 @@ int dwm_main(const char *const new_program_title)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* select events */
|
/* select events */
|
||||||
wa.cursor = cursor[CurNormal]->cursor;
|
wa.cursor = cursors[CURSOR_NORMAL];
|
||||||
wa.event_mask =
|
wa.event_mask =
|
||||||
SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask |
|
SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask |
|
||||||
PointerMotionMask | EnterWindowMask | LeaveWindowMask |
|
PointerMotionMask | EnterWindowMask | LeaveWindowMask |
|
||||||
|
@ -289,10 +286,7 @@ int dwm_main(const char *const new_program_title)
|
||||||
monitor_destroy(mons);
|
monitor_destroy(mons);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < CurLast; i++) {
|
cursors_destroy(drw->dpy);
|
||||||
drw_cur_free(drw, cursor[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
scheme_destroy();
|
scheme_destroy();
|
||||||
|
|
||||||
wmcheckwin_destroy();
|
wmcheckwin_destroy();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _DWM_H
|
#define _DWM_H
|
||||||
|
|
||||||
#include "config/buttons.h"
|
#include "config/buttons.h"
|
||||||
|
#include "config/cursors.h"
|
||||||
#include "config/keys.h"
|
#include "config/keys.h"
|
||||||
#include "config/layouts.h"
|
#include "config/layouts.h"
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ void movemouse(__attribute__((unused)) const Arg *arg)
|
||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
None,
|
None,
|
||||||
cursor[CurMove]->cursor,
|
cursors[CURSOR_MOVE],
|
||||||
CurrentTime
|
CurrentTime
|
||||||
) != GrabSuccess
|
) != GrabSuccess
|
||||||
) {
|
) {
|
||||||
|
@ -357,7 +357,7 @@ void resizemouse(__attribute__((unused)) const Arg *arg)
|
||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
None,
|
None,
|
||||||
cursor[CurResize]->cursor,
|
cursors[CURSOR_RESIZE],
|
||||||
CurrentTime
|
CurrentTime
|
||||||
) != GrabSuccess
|
) != GrabSuccess
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in a new issue