mirror of
https://github.com/vale981/bspwm
synced 2025-03-05 09:51:38 -05:00
socket client
This commit is contained in:
parent
10599b94f0
commit
7aa12b0cd6
8 changed files with 56 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
bspwm
|
bspwm
|
||||||
|
bspc
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
# CFLAGS=-Wall -g -pendantic
|
# CFLAGS=-Wall -g -pendantic
|
||||||
|
|
||||||
all:
|
all:
|
||||||
gcc -std=c99 -Wall -g -pedantic -llua -lxcb -o bspwm main.c utils.c settings.c luautils.c messages.c events.c
|
gcc -std=c99 -Wall -g -pedantic -llua -lxcb -o bspwm bspwm.c utils.c settings.c luautils.c messages.c events.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f bspwm
|
rm -f bspwm
|
||||||
|
|
40
bspc.c
Normal file
40
bspc.c
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define SOCK_PATH "BSPWM_SOCKET"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int sock_fd, i;
|
||||||
|
struct sockaddr_un sock_address;
|
||||||
|
char *sock_path;
|
||||||
|
char response[BUFSIZ];
|
||||||
|
int num_args = argc - 1;
|
||||||
|
char **args = (argv + 1);
|
||||||
|
|
||||||
|
if (num_args < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sock_path = getenv(SOCK_PATH);
|
||||||
|
|
||||||
|
if (sock_path == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sock_address.sun_family = AF_UNIX;
|
||||||
|
strcpy(sock_address.sun_path, sock_path);
|
||||||
|
|
||||||
|
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
connect(sock_fd, (struct sockaddr *) &sock_address, sizeof(sock_address));
|
||||||
|
|
||||||
|
for (i = 0; i < num_args; i++) {
|
||||||
|
send(sock_fd, args[i], strlen(args[i]), 0);
|
||||||
|
|
||||||
|
if (recv(sock_fd, response, sizeof(response), 0) > 0)
|
||||||
|
printf("%s\n", response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
2
bspwm.c
2
bspwm.c
|
@ -10,7 +10,7 @@
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "main.h"
|
#include "bspwm.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
|
|
4
bspwm.h
4
bspwm.h
|
@ -16,8 +16,8 @@ enum { NET_SUPPORTED, NET_FULLSCREEN, NET_WM_STATE, NET_ACTIVE, NET_COUNT };
|
||||||
|
|
||||||
static xcb_atom_t wmatoms[WM_COUNT], netatoms[NET_COUNT];
|
static xcb_atom_t wmatoms[WM_COUNT], netatoms[NET_COUNT];
|
||||||
|
|
||||||
int xcb_check_other_wm(void);
|
int register_events(void);
|
||||||
xcb_screen_t *screen_of_display(xcb_connection_t*, int);
|
xcb_screen_t *screen_of_display(xcb_connection_t *, int);
|
||||||
void sigchld(int);
|
void sigchld(int);
|
||||||
void setup(int);
|
void setup(int);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ int eval_expr(lua_State *L, char *expr)
|
||||||
return luaL_dostring(L, buf);
|
return luaL_dostring(L, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_hastable(lua_State *L, char *name)
|
int has_table(lua_State *L, char *name)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
eval_expr(L, name);
|
eval_expr(L, name);
|
||||||
|
@ -55,7 +55,7 @@ int int_expr(lua_State *L, char *expr, int fallback)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lua_boolexpr(lua_State *L, char *expr, bool fallback)
|
bool bool_expr(lua_State *L, char *expr, bool fallback)
|
||||||
{
|
{
|
||||||
bool result = fallback;
|
bool result = fallback;
|
||||||
if (eval_expr(L, expr) == 0) {
|
if (eval_expr(L, expr) == 0) {
|
||||||
|
|
12
luautils.h
12
luautils.h
|
@ -6,11 +6,11 @@
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
|
|
||||||
int eval_expr(lua_State*, char*);
|
int eval_expr(lua_State *, char *);
|
||||||
int lua_hastable(lua_State*, char*);
|
int has_table(lua_State *, char *);
|
||||||
char *string_expr(lua_State*, char*, char*);
|
char *string_expr(lua_State *, char *, char *);
|
||||||
double double_expr(lua_State*, char*, double);
|
double double_expr(lua_State *, char *, double);
|
||||||
int int_expr(lua_State*, char*, int);
|
int int_expr(lua_State *, char *, int);
|
||||||
bool lua_boolexpr(lua_State*, char*, bool);
|
bool bool_expr(lua_State *, char *, bool);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,7 +26,7 @@ void apply_settings(lua_State *L)
|
||||||
{
|
{
|
||||||
normal_border_color = string_expr(L, "normal_border_color", NORMAL_BORDER_COLOR);
|
normal_border_color = string_expr(L, "normal_border_color", NORMAL_BORDER_COLOR);
|
||||||
split_ratio = double_expr(L, "split_ratio", SPLIT_RATIO);
|
split_ratio = double_expr(L, "split_ratio", SPLIT_RATIO);
|
||||||
smart_surroundings = lua_boolexpr(L, "smart_surroundings", SMART_SURROUNDINGS);
|
smart_surroundings = bool_expr(L, "smart_surroundings", SMART_SURROUNDINGS);
|
||||||
outer_border_width = int_expr(L, "outer_border_width", OUTER_BORDER_WIDTH);
|
outer_border_width = int_expr(L, "outer_border_width", OUTER_BORDER_WIDTH);
|
||||||
inner_border_width = int_expr(L, "inner_border_width", INNER_BORDER_WIDTH);
|
inner_border_width = int_expr(L, "inner_border_width", INNER_BORDER_WIDTH);
|
||||||
inner_border_color = string_expr(L, "inner_border_color", INNER_BORDER_COLOR);
|
inner_border_color = string_expr(L, "inner_border_color", INNER_BORDER_COLOR);
|
||||||
|
@ -44,7 +44,7 @@ void get_setting(lua_State *L)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
if (!lua_hastable(L, "get"))
|
if (!has_table(L, "get"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
name = string_expr(L, "get.name", NULL);
|
name = string_expr(L, "get.name", NULL);
|
||||||
|
@ -63,7 +63,7 @@ void set_setting(lua_State *L)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
if (!lua_hastable(L, "set"))
|
if (!has_table(L, "set"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
name = string_expr(L, "set.name", NULL);
|
name = string_expr(L, "set.name", NULL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue