Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
HarveyHunt committed Apr 21, 2015
2 parents 787016a + 072c8d0 commit 1fdc95d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Contents
* [Installation](#installation)
* [Commandline Arguments](#commandline-arguments)
* [Configuration](#configuration)
* [Changing Socket Path](#changing-socket-path)
* [Keybinds](#keybinds)
* [Scratchpad](#scratchpad)
* [Motions](#motions)
Expand Down Expand Up @@ -90,6 +91,13 @@ Note: When configuring colours in ```howmrc```, enclose the colour in quotes, su
cottage -c border_focus "#343434"
```

##Changing Socket Path
By default, howm will attempt to create a socket at ```/tmp/howm```, this can be overwritten by setting the environment variable ```HOWM_SOCK```. For example:

```
export HOW_SOCK=/tmp/howm_test
```

##Keybinds

Keybinds are now placed in multiple [sxhkd](https://github.com/baskerville/sxhkd) files.
Expand Down
1 change: 1 addition & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <xcb/xproto.h>
#include <xcb/xcb.h>

#include "types.h"

Expand Down
23 changes: 15 additions & 8 deletions src/howm.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void setup(void)
{
unsigned int i;

for (i = 1; i < WORKSPACES; i++) {
for (i = 1; i <= WORKSPACES; i++) {
wss[i].layout = WS_DEF_LAYOUT;
wss[i].bar_height = conf.bar_height;
wss[i].master_ratio = MASTER_RATIO;
Expand Down Expand Up @@ -136,7 +136,7 @@ int main(int argc, char *argv[])
ssize_t n;
xcb_generic_event_t *ev;
char ch;
char conf_path[128];
char conf_path[128] = {0};
char *data = calloc(IPC_BUF_SIZE, sizeof(char));

if (!data) {
Expand All @@ -146,15 +146,25 @@ int main(int argc, char *argv[])

conf_path[0] = '\0';

while ((ch = getopt(argc, argv, "c:")) != -1) {
while ((ch = getopt(argc, argv, "vhc:")) != -1) {
switch (ch) {
case 'c':
snprintf(conf_path, sizeof(conf_path), "%s", optarg);
break;
case 'v':
printf("%s\n", VERSION);
exit(EXIT_SUCCESS);
case 'h':
printf("%s: %s", WM_NAME, "[-v|-h|-c CONFIG_PATH]\n");
exit(EXIT_SUCCESS);
}
}

/* TODO: Add default config paths. */
if (conf_path[0] == '\0') {
snprintf(conf_path, sizeof(conf_path), "%s/%s/%s/%s", getenv("HOME"),
".config", WM_NAME, CONF_NAME);
log_err("Using default config path: %s", conf_path);
}

dpy = xcb_connect(NULL, NULL);
if (xcb_connection_has_error(dpy)) {
Expand All @@ -165,10 +175,7 @@ int main(int argc, char *argv[])
sock_fd = ipc_init();
check_other_wm();
dpy_fd = xcb_get_file_descriptor(dpy);
if (conf_path[0] != '\0')
exec_config(conf_path);
else
log_err("No config path was supplied");
exec_config(conf_path);

while (running) {
if (!xcb_flush(dpy))
Expand Down
11 changes: 8 additions & 3 deletions src/howm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#include "layout.h"
#include "types.h"

#define WORKSPACES 5
#define IPC_BUF_SIZE 1024
#define VERSION "0.5.1"
#define WM_NAME "howm"
#define CONF_NAME "howmrc"
#define HOWM_PATH "/usr/bin/howm"
#define SOCK_PATH "/tmp/howm"
#define ENV_SOCK_VAR "HOWM_SOCK"
#define DEF_SOCK_PATH "/tmp/howm"
#define IPC_BUF_SIZE 1024

#define WORKSPACES 5
#define WS_DEF_LAYOUT HSTACK
#define MASTER_RATIO 0.6
#define DEF_BORDER_FOCUS "#70898F"
Expand Down
52 changes: 49 additions & 3 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,32 @@ static int ipc_process_function(char **args);
static int ipc_process_config(char **args);
static bool ipc_arg_to_bool(char *arg, int *err);

/**
* @brief Open a socket and return it.
*
* If a socket path is defined in the env variable defined as ENV_SOCK_VAR then
* use that - else use DEF_SOCK_PATH.
*
* @return A socket file descriptor.
*/
int ipc_init(void)
{
struct sockaddr_un addr;
char *sp = NULL;
char sock_path[256];
int sock_fd;

sp = getenv(ENV_SOCK_VAR);

if (sp)
snprintf(sock_path, sizeof(sock_path), "%s", sp);
else
snprintf(sock_path, sizeof(sock_path), "%s", DEF_SOCK_PATH);

memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", SOCK_PATH);
unlink(SOCK_PATH);
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", sock_path);
unlink(sock_path);
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);

if (sock_fd == -1) {
Expand All @@ -88,6 +105,15 @@ int ipc_init(void)
return sock_fd;
}

/**
* @brief Process a message depending on its type - a config message or a
* function call message.
*
* @param msg A buffer containing the message sent by cottage.
* @param len The length of the message.
*
* @return An error code resulting from processing msg.
*/
int ipc_process(char *msg, int len)
{
int err = IPC_ERR_NONE;
Expand Down Expand Up @@ -319,13 +345,21 @@ static char **ipc_process_args(char *msg, int len, int *err)
return args;
}

/**
* @brief Process a config message. If the config option isn't recognised, set
* err to IPC_ERR_NO_CONFIG.
*
* @param args An array of strings representing the args.
*
* @return err containing the error (or lack of) that has occurred.
*/
static int ipc_process_config(char **args)
{
int err = IPC_ERR_NONE;
int i = 0;
bool b = false;

if (!(args + 1))
if (!args[0] || !args[1])
return IPC_ERR_TOO_FEW_ARGS;

if (strcmp("border_px", *args) == 0)
Expand Down Expand Up @@ -362,10 +396,22 @@ static int ipc_process_config(char **args)
SET_COLOUR(conf.border_prev_focus, *(args + 1));
else if (strcmp("border_urgent", *args) == 0)
SET_COLOUR(conf.border_urgent, *(args + 1));
else
err = IPC_ERR_NO_CONFIG;
update_focused_client(wss[cw].current);
return err;
}

/**
* @brief Convert an argument to a boolean.
*
* t and 1 are considered true, f and 0 are considered false.
*
* @param arg A string containing the argument.
* @param err Where an error code should be stored.
*
* @return A boolean, depending on whether the argument was true or false.
*/
static bool ipc_arg_to_bool(char *arg, int *err)
{
if (strcmp("true", arg) == 0
Expand Down
2 changes: 1 addition & 1 deletion src/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
enum ipc_errs { IPC_ERR_NONE, IPC_ERR_SYNTAX, IPC_ERR_ALLOC, IPC_ERR_NO_FUNC,
IPC_ERR_TOO_MANY_ARGS, IPC_ERR_TOO_FEW_ARGS, IPC_ERR_ARG_NOT_INT,
IPC_ERR_ARG_NOT_BOOL, IPC_ERR_ARG_TOO_LARGE, IPC_ERR_ARG_TOO_SMALL,
IPC_ERR_UNKNOWN_TYPE };
IPC_ERR_UNKNOWN_TYPE, IPC_ERR_NO_CONFIG };
enum arg_types { TYPE_IGNORE, TYPE_INT, TYPE_STR };

int ipc_init(void);
Expand Down

0 comments on commit 1fdc95d

Please sign in to comment.