mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-05-19 09:30:24 -07:00
big poosh
This commit is contained in:
parent
fbf145e5af
commit
d9f72fdffc
4
Makefile
4
Makefile
@ -8,8 +8,8 @@ ALL_LDFLAGS = $(LDFLAGS) $(LIBS) -lxcb
|
|||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
||||||
OBJ = src/event.o src/action.o src/sowm.o
|
OBJ = src/event.o src/sowm.o
|
||||||
HDR = src/event.h src/action.h src/globals.h
|
HDR = src/event.h src/globals.h
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) $(ALL_CFLAGS) -c -o $@ $<
|
$(CC) $(ALL_CFLAGS) -c -o $@ $<
|
||||||
|
4
design.txt
Normal file
4
design.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
keybindings
|
||||||
|
events
|
||||||
|
actions
|
||||||
|
manager
|
37
src/action.c
37
src/action.c
@ -1,37 +0,0 @@
|
|||||||
#include "action.h"
|
|
||||||
|
|
||||||
void action_win_add() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_del() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_center() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_fullscreen() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_focus() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_kill() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_next() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_win_to_desktop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_to_desktop() {
|
|
||||||
|
|
||||||
}
|
|
11
src/action.h
11
src/action.h
@ -1,11 +0,0 @@
|
|||||||
/* todo */
|
|
||||||
void action_win_add(void);
|
|
||||||
void action_win_center(void);
|
|
||||||
void action_win_del(void);
|
|
||||||
void action_win_fullscreen(void);
|
|
||||||
void action_win_focus(void);
|
|
||||||
void action_win_kill(void);
|
|
||||||
void action_win_prev(void);
|
|
||||||
void action_win_next(void);
|
|
||||||
void action_win_to_desktop(void);
|
|
||||||
void action_to_desktop(void);
|
|
19
src/event.c
19
src/event.c
@ -10,10 +10,10 @@ static xcb_window_t motion_win;
|
|||||||
void (*events[XCB_NO_OPERATION])(xcb_generic_event_t *) = {
|
void (*events[XCB_NO_OPERATION])(xcb_generic_event_t *) = {
|
||||||
[XCB_BUTTON_PRESS] = event_button_press,
|
[XCB_BUTTON_PRESS] = event_button_press,
|
||||||
[XCB_BUTTON_RELEASE] = event_button_release,
|
[XCB_BUTTON_RELEASE] = event_button_release,
|
||||||
[XCB_CONFIGURE_REQUEST] = event_configure_request,
|
/* [XCB_CONFIGURE_REQUEST] = event_configure_request, */
|
||||||
[XCB_KEY_PRESS] = event_key_press,
|
/* [XCB_KEY_PRESS] = event_key_press, */
|
||||||
[XCB_CREATE_NOTIFY] = event_notify_create,
|
[XCB_CREATE_NOTIFY] = event_notify_create,
|
||||||
[XCB_DESTROY_NOTIFY] = event_notify_destroy,
|
/* [XCB_DESTROY_NOTIFY] = event_notify_destroy, */
|
||||||
[XCB_ENTER_NOTIFY] = event_notify_enter,
|
[XCB_ENTER_NOTIFY] = event_notify_enter,
|
||||||
[XCB_MOTION_NOTIFY] = event_notify_motion
|
[XCB_MOTION_NOTIFY] = event_notify_motion
|
||||||
};
|
};
|
||||||
@ -47,17 +47,18 @@ void event_button_press(xcb_generic_event_t *ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void event_button_release(xcb_generic_event_t *ev) {
|
void event_button_release(xcb_generic_event_t *ev) {
|
||||||
|
(void)(ev);
|
||||||
xcb_ungrab_pointer(dpy, XCB_CURRENT_TIME);
|
xcb_ungrab_pointer(dpy, XCB_CURRENT_TIME);
|
||||||
motion_win = 0;
|
motion_win = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_configure_request(xcb_generic_event_t *ev) {
|
/* void event_configure_request(xcb_generic_event_t *ev) { */
|
||||||
|
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
void event_key_press(xcb_generic_event_t *ev) {
|
/* void event_key_press(xcb_generic_event_t *ev) { */
|
||||||
|
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
void event_notify_create(xcb_generic_event_t *ev) {
|
void event_notify_create(xcb_generic_event_t *ev) {
|
||||||
xcb_create_notify_event_t *e = (xcb_create_notify_event_t *)ev;
|
xcb_create_notify_event_t *e = (xcb_create_notify_event_t *)ev;
|
||||||
@ -74,9 +75,9 @@ void event_notify_create(xcb_generic_event_t *ev) {
|
|||||||
e->window, XCB_CURRENT_TIME);
|
e->window, XCB_CURRENT_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_notify_destroy(xcb_generic_event_t *ev) {
|
/* void event_notify_destroy(xcb_generic_event_t *ev) { */
|
||||||
|
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
void event_notify_enter(xcb_generic_event_t *ev) {
|
void event_notify_enter(xcb_generic_event_t *ev) {
|
||||||
xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *)ev;
|
xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *)ev;
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
void event_button_press(xcb_generic_event_t *ev);
|
void event_button_press(xcb_generic_event_t *ev);
|
||||||
void event_button_release(xcb_generic_event_t *ev);
|
void event_button_release(xcb_generic_event_t *ev);
|
||||||
void event_configure_request(xcb_generic_event_t *ev);
|
/* void event_configure_request(xcb_generic_event_t *ev); */
|
||||||
void event_key_press(xcb_generic_event_t *ev);
|
/* void event_key_press(xcb_generic_event_t *ev); */
|
||||||
void event_notify_create(xcb_generic_event_t *ev);
|
void event_notify_create(xcb_generic_event_t *ev);
|
||||||
void event_notify_destroy(xcb_generic_event_t *ev);
|
/* void event_notify_destroy(xcb_generic_event_t *ev); */
|
||||||
void event_notify_enter(xcb_generic_event_t *ev);
|
void event_notify_enter(xcb_generic_event_t *ev);
|
||||||
void event_notify_motion(xcb_generic_event_t *ev);
|
void event_notify_motion(xcb_generic_event_t *ev);
|
||||||
|
|
||||||
|
@ -2,3 +2,10 @@
|
|||||||
|
|
||||||
extern xcb_connection_t *dpy;
|
extern xcb_connection_t *dpy;
|
||||||
extern xcb_screen_t *scr;
|
extern xcb_screen_t *scr;
|
||||||
|
|
||||||
|
struct desktop {
|
||||||
|
xcb_window_t *windows;
|
||||||
|
int num;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int current_desktop;
|
||||||
|
35
src/sowm.c
35
src/sowm.c
@ -5,16 +5,22 @@
|
|||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
#include "vec.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
static void init_wm(void);
|
static void init_wm(void);
|
||||||
static void init_input(void);
|
static void init_input(void);
|
||||||
|
static void init_desktops(void);
|
||||||
|
|
||||||
xcb_connection_t *dpy;
|
xcb_connection_t *dpy;
|
||||||
xcb_screen_t *scr;
|
xcb_screen_t *scr;
|
||||||
|
|
||||||
static void init_wm(void) {
|
struct desktop *desktops;
|
||||||
uint32_t values[2];
|
int current_desktop = 0;
|
||||||
|
|
||||||
|
static void init_wm() {
|
||||||
|
uint32_t values;
|
||||||
|
|
||||||
dpy = xcb_connect(NULL, NULL);
|
dpy = xcb_connect(NULL, NULL);
|
||||||
|
|
||||||
@ -31,29 +37,41 @@ static void init_wm(void) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
|
values = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
|
||||||
|
|
||||||
xcb_change_window_attributes_checked(dpy, scr->root,
|
xcb_change_window_attributes_checked(dpy, scr->root,
|
||||||
XCB_CW_EVENT_MASK, values);
|
XCB_CW_EVENT_MASK, &values);
|
||||||
|
|
||||||
xcb_flush(dpy);
|
xcb_flush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_input(void) {
|
static void init_input() {
|
||||||
xcb_grab_key(dpy, 1, scr->root, XCB_MOD_MASK_1, XCB_NO_SYMBOL,
|
xcb_grab_key(dpy, 1, scr->root, SOWM_MOD, XCB_NO_SYMBOL,
|
||||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||||
|
|
||||||
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
||||||
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
||||||
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, XCB_MOD_MASK_1);
|
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, SOWM_MOD);
|
||||||
|
|
||||||
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
||||||
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
||||||
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 3, XCB_MOD_MASK_1);
|
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 3, SOWM_MOD);
|
||||||
|
|
||||||
xcb_flush(dpy);
|
xcb_flush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void init_desktops() {
|
||||||
|
struct desktop new = {0};
|
||||||
|
|
||||||
|
for (int i = 0; i < SOWM_NUM_DESKTOPS; i++) {
|
||||||
|
new.num = i;
|
||||||
|
vec_push_back(desktops, new);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* todo finish usage of desktops */
|
||||||
|
vec_free(desktops);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
xcb_generic_event_t *ev;
|
xcb_generic_event_t *ev;
|
||||||
unsigned int ev_type;
|
unsigned int ev_type;
|
||||||
@ -67,6 +85,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
init_wm();
|
init_wm();
|
||||||
init_input();
|
init_input();
|
||||||
|
init_desktops();
|
||||||
|
|
||||||
while ((ev = xcb_wait_for_event(dpy))) {
|
while ((ev = xcb_wait_for_event(dpy))) {
|
||||||
ev_type = ev->response_type & ~0x80;
|
ev_type = ev->response_type & ~0x80;
|
||||||
|
175
src/vec.h
Normal file
175
src/vec.h
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
This is an implementation of a std::vector like growable array, but in plain
|
||||||
|
C89 code. The result is a type safe, easy to use, dynamic array that has a
|
||||||
|
familiar set of operations. Source: https://github.com/eteran/c-vector
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2020 Dylan Araps
|
||||||
|
Copyright (c) 2015 Evan Teran
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VEC_H_
|
||||||
|
#define VEC_H_
|
||||||
|
|
||||||
|
#include <assert.h> /* for assert */
|
||||||
|
#include <stddef.h> /* for size_t */
|
||||||
|
#include <stdlib.h> /* for malloc/realloc/free */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_set_capacity - For internal use, set capacity variable.
|
||||||
|
* @param vec - the vector
|
||||||
|
* @param size - the new capacity to set
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_set_capacity(vec, size) \
|
||||||
|
do { \
|
||||||
|
if (vec) { \
|
||||||
|
((size_t *)(vec))[-1] = (size); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_set_size - For internal use, sets the size variable of the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @param size - the new capacity to set
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_set_size(vec, size) \
|
||||||
|
do { \
|
||||||
|
if (vec) { \
|
||||||
|
((size_t *)(vec))[-2] = (size); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_capacity - gets the current capacity of the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return the capacity as a size_t
|
||||||
|
*/
|
||||||
|
#define vec_capacity(vec) ((vec) ? ((size_t *)(vec))[-1] : (size_t)0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_size - gets the current size of the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return the size as a size_t
|
||||||
|
*/
|
||||||
|
#define vec_size(vec) ((vec) ? ((size_t *)(vec))[-2] : (size_t)0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_empty - returns non-zero if the vector is empty
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return non-zero if empty, zero if non-empty
|
||||||
|
*/
|
||||||
|
#define vec_empty(vec) (vec_size(vec) == 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_grow - For internal use, ensure that the vector is >= <count>.
|
||||||
|
* @param vec - the vector
|
||||||
|
* @param size - the new capacity to set
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_grow(vec, count) \
|
||||||
|
do { \
|
||||||
|
const size_t vec__sz = (count) * sizeof(*(vec)) + (sizeof(size_t) * 2); \
|
||||||
|
if (!(vec)) { \
|
||||||
|
size_t *vec__p = malloc(vec__sz); \
|
||||||
|
assert(vec__p); \
|
||||||
|
(vec) = (void *)(&vec__p[2]); \
|
||||||
|
vec_set_capacity((vec), (count)); \
|
||||||
|
vec_set_size((vec), 0); \
|
||||||
|
} else { \
|
||||||
|
size_t *vec__p1 = &((size_t *)(vec))[-2]; \
|
||||||
|
size_t *vec__p2 = realloc(vec__p1, (vec__sz)); \
|
||||||
|
assert(vec__p2); \
|
||||||
|
(vec) = (void *)(&vec__p2[2]); \
|
||||||
|
vec_set_capacity((vec), (count)); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_pop_back - removes the last element from the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_pop_back(vec) \
|
||||||
|
do { \
|
||||||
|
vec_set_size((vec), vec_size(vec) - 1); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_erase - removes the element at index i from the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @param i - index of element to remove
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_erase(vec, i) \
|
||||||
|
do { \
|
||||||
|
if (vec) { \
|
||||||
|
const size_t vec__sz = vec_size(vec); \
|
||||||
|
if ((i) < vec__sz) { \
|
||||||
|
vec_set_size((vec), vec__sz - 1); \
|
||||||
|
size_t vec__x; \
|
||||||
|
for (vec__x = (i); vec__x < (vec__sz - 1); ++vec__x) { \
|
||||||
|
(vec)[vec__x] = (vec)[vec__x + 1]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_free - frees all memory associated with the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_free(vec) \
|
||||||
|
do { \
|
||||||
|
if (vec) { \
|
||||||
|
size_t *p1 = &((size_t *)(vec))[-2]; \
|
||||||
|
free(p1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_end - returns an iterator to one past the last element
|
||||||
|
* @param vec - the vector
|
||||||
|
* @return a pointer to one past the last element (or NULL)
|
||||||
|
*/
|
||||||
|
#define vec_end(vec) ((vec) ? &((vec)[vec_size(vec)]) : NULL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief vec_push_back - adds an element to the end of the vector
|
||||||
|
* @param vec - the vector
|
||||||
|
* @param value - the value to add
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
#define vec_push_back(vec, value) \
|
||||||
|
do { \
|
||||||
|
size_t vec__cap = vec_capacity(vec); \
|
||||||
|
if (vec__cap <= vec_size(vec)) { \
|
||||||
|
vec_grow((vec), !vec__cap ? vec__cap + 1 : vec__cap * 2); \
|
||||||
|
} \
|
||||||
|
vec[vec_size(vec)] = (value); \
|
||||||
|
vec_set_size((vec), vec_size(vec) + 1); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif /* VEC_H_ */
|
Loading…
x
Reference in New Issue
Block a user