Skip to content

Commit

Permalink
released at 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpcpc authored Nov 12, 2020
1 parent 90dd85f commit c8823da
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed
- string.h library dependency.

## [0.0.4] - 20202-11-10
## [0.0.4] - 2020-11-10
### Added
- Instructions for patches and the patching process.
- Minimum window height and width parameters.
Expand All @@ -34,7 +34,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Crash when pointer x/y cords less than window origin.

## [0.0.5] - 20202-11-11
## [0.0.5] - 2020-11-11
### Added
- Default key bindings in man page.
- Disclaimer section in README.

## [0.0.6] - 2020-11-12
### Added
- Window borders and color definitions.
2 changes: 0 additions & 2 deletions TODO

This file was deleted.

20 changes: 12 additions & 8 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
* XCB_MOD_MASK_ANY
*/

#define MOD1 XCB_MOD_MASK_4
#define MOD2 XCB_MOD_MASK_SHIFT
#define MOD1 XCB_MOD_MASK_4
#define MOD2 XCB_MOD_MASK_SHIFT

/* DEFAULT WINDOW PROPERTIES
* The following parameters can be used to change window and new
* window behavior
* The following parameters can be used to change existing and new
* window behavior.
*/

#define WINDOW_WIDTH 600
#define WINDOW_HEIGHT 400
#define WINDOW_MIN_WIDTH 60
#define WINDOW_MIN_HEIGHT 40
#define WINDOW_WIDTH 600
#define WINDOW_HEIGHT 400
#define WINDOW_MIN_WIDTH 60
#define WINDOW_MIN_HEIGHT 40
#define BORDER_WIDTH 2 /* 0 = no border effect */
#define BORDER_COLOR_UNFOCUSED 0x00FFFF /* 0xRRGGBB */
#define BORDER_COLOR_FOCUSED 0xFFFFFF /* 0xRRGGBB */

/* ALIASED COMMANDS
* Each space delimited argument should be passed as an additional
Expand All @@ -50,3 +53,4 @@ static Key keys[] = {
{ MOD1, 0x0071, killclient, NULL }, /* 0x0071 = XK_q */
{ MOD1|MOD2, 0x0071, closewm, NULL } /* 0x0071 = XK_q */
};

50 changes: 40 additions & 10 deletions xwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ static void setFocus(xcb_drawable_t window) {
}
}

static void setBorderColor(xcb_window_t window, int focus) {
if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) {
uint32_t vals[1];
vals[0] = focus ? BORDER_COLOR_FOCUSED : BORDER_COLOR_UNFOCUSED;
xcb_change_window_attributes(dpy, window, XCB_CW_BORDER_PIXEL, vals);
xcb_flush(dpy);
}
}

static void setBorderWidth(xcb_window_t window) {
if ((BORDER_WIDTH > 0) && (scre->root != window) && (0 != window)) {
uint32_t vals[2];
vals[0] = BORDER_WIDTH;
xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_BORDER_WIDTH, vals);
xcb_flush(dpy);
}
}

static void setWindowDimensions(xcb_window_t window) {
if ((scre->root != window) && (0 != window)) {
uint32_t vals[2];
vals[0] = WINDOW_WIDTH;
vals[1] = WINDOW_HEIGHT;
xcb_configure_window(dpy, window, XCB_CONFIG_WINDOW_WIDTH |
XCB_CONFIG_WINDOW_HEIGHT, vals);
xcb_flush(dpy);
}
}

static void handleKeyPress(xcb_generic_event_t * ev) {
xcb_key_press_event_t * e = ( xcb_key_press_event_t *) ev;
xcb_keysym_t keysym = xcb_get_keysym(e->detail);
Expand All @@ -119,6 +148,12 @@ static void handleKeyPress(xcb_generic_event_t * ev) {
static void handleEnterNotify(xcb_generic_event_t * ev) {
xcb_enter_notify_event_t * e = ( xcb_enter_notify_event_t *) ev;
setFocus(e->event);
setBorderColor(e->event, 1);
}

static void handleLeaveNotify(xcb_generic_event_t * ev) {
xcb_leave_notify_event_t * e = ( xcb_leave_notify_event_t *) ev;
setBorderColor(e->event, 0);
}

static void handleButtonRelease(xcb_generic_event_t * ev) {
Expand All @@ -137,15 +172,10 @@ static void handleDestroyNotify(xcb_generic_event_t * ev) {
static void handleMapRequest(xcb_generic_event_t * ev) {
xcb_map_request_event_t * e = (xcb_map_request_event_t *) ev;
xcb_map_window(dpy, e->window);
if ((scre->root != e->window) && (0 != e->window)) {
uint32_t vals[2];
vals[0] = WINDOW_WIDTH;
vals[1] = WINDOW_HEIGHT;
xcb_configure_window(dpy, e->window, XCB_CONFIG_WINDOW_WIDTH |
XCB_CONFIG_WINDOW_HEIGHT, vals);
xcb_flush(dpy);
}
values[0] = XCB_EVENT_MASK_ENTER_WINDOW;
setWindowDimensions(e->window);
setBorderWidth(e->window);
setBorderColor(e->window, 0);
values[0] = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW;
xcb_change_window_attributes_checked(dpy, e->window,
XCB_CW_EVENT_MASK, values);
setFocus(e->window);
Expand Down Expand Up @@ -221,7 +251,7 @@ static int strcmp_c(char * str1, char * str2) {
int main(int argc, char * argv[]) {
int ret = 0;
if ((argc == 2) && (strcmp_c("-v", argv[1]) == 0)) {
ret = die("xwm-0.0.5, © 2020 Michael Czigler, see LICENSE for details\n");
ret = die("xwm-0.0.6, © 2020 Michael Czigler, see LICENSE for details\n");
}
if ((ret == 0) && (argc != 1)) {
ret = die("usage: xwm [-v]\n");
Expand Down
8 changes: 8 additions & 0 deletions xwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ static void killclient(char **com);
static void spawn(char **com);
static void closewm(char ** com);

/* window behavior */
static void setFocus(xcb_drawable_t window);
static void setWindowDimensions(xcb_drawable_t window);
static void setBorderWidth(xcb_drawable_t window);
static void setBorderColor(xcb_drawable_t window, int focus);

/* event hander actions */
static int eventHandler(void);
static void handleMotionNotify(xcb_generic_event_t * ev);
static void handleEnterNotify(xcb_generic_event_t * ev);
static void handleLeaveNotify(xcb_generic_event_t * ev);
static void handleDestroyNotify(xcb_generic_event_t * ev);
static void handleButtonPress(xcb_generic_event_t * ev);
static void handleButtonRelease(xcb_generic_event_t * ev);
Expand All @@ -35,6 +42,7 @@ static void handleMapRequest(xcb_generic_event_t * ev);
static handler_func_t handler_funs[] = {
{ XCB_MOTION_NOTIFY, handleMotionNotify },
{ XCB_ENTER_NOTIFY, handleEnterNotify },
{ XCB_LEAVE_NOTIFY, handleLeaveNotify },
{ XCB_DESTROY_NOTIFY, handleDestroyNotify },
{ XCB_BUTTON_PRESS, handleButtonPress },
{ XCB_BUTTON_RELEASE, handleButtonRelease },
Expand Down

0 comments on commit c8823da

Please sign in to comment.