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