apply env patch

master
Ryan 2023-09-25 18:49:44 -04:00
parent f69b91e548
commit c86e057c2c
Signed by: ryan
GPG Key ID: 7D7E2E94267DAD95
4 changed files with 223 additions and 5 deletions

View File

@ -16,7 +16,7 @@ LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS)
all: dwl
dwl: dwl.o util.o dwl-ipc-unstable-v2-protocol.o
$(CC) dwl.o util.o dwl-ipc-unstable-v2-protocol.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@
dwl.o: dwl.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-ipc-unstable-v2-protocol.h
dwl.o: dwl.c env.c config.mk config.h client.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h dwl-ipc-unstable-v2-protocol.h
util.o: util.c util.h
dwl-ipc-unstable-v2-protocol.o: dwl-ipc-unstable-v2-protocol.h

View File

@ -1,9 +1,10 @@
/* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const float bordercolor[] = {0.5, 0.5, 0.5, 1.0};
static const float focuscolor[] = {1.0, 0.0, 0.0, 1.0};
static unsigned int borderpx = 1; /* border pixel of windows */
static float rootcolor[] = {0.3, 0.3, 0.3, 1.0};
static float bordercolor[] = {0.5, 0.5, 0.5, 1.0};
static float focuscolor[] = {1.0, 0.0, 0.0, 1.0};
/* To conform the xdg-protocol, set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0};

6
dwl.c
View File

@ -442,6 +442,8 @@ static Atom netatom[NetLast];
/* attempt to encapsulate suck into one file */
#include "client.h"
#include "env.c"
static pid_t *autostart_pids;
static size_t autostart_len;
@ -655,7 +657,6 @@ buttonpress(struct wl_listener *listener, void *data)
xytonode(cursor->x, cursor->y, NULL, &c, NULL, NULL, NULL);
if (c && (!client_is_unmanaged(c) || client_wants_focus(c)))
focusclient(c, 1);
keyboard = wlr_seat_get_keyboard(seat);
mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
for (b = buttons; b < END(buttons); b++) {
@ -1133,6 +1134,8 @@ createpointer(struct wlr_pointer *pointer)
libinput_device_config_accel_set_profile(libinput_device, accel_profile);
libinput_device_config_accel_set_speed(libinput_device, accel_speed);
}
inputconfig(libinput_device);
}
wlr_cursor_attach_input_device(cursor, &pointer->base);
@ -3210,6 +3213,7 @@ main(int argc, char *argv[])
/* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */
if (!getenv("XDG_RUNTIME_DIR"))
die("XDG_RUNTIME_DIR must be set");
loadtheme();
setup();
run(startup_cmd);
cleanup();

213
env.c Normal file
View File

@ -0,0 +1,213 @@
static int
isenabled(const char *val, int def)
{
return ((def && (!val || !val[0] || (val[0] != '0'))) || (!def && (val && val[0] && (val[0] != '0'))));
}
static void
setclickmethod(struct libinput_device *libinput_device)
{
const char *val;
long l;
char *end = NULL;
val = getenv("LIBINPUT_DEFAULT_CLICK_METHOD");
if (!val || !val[0])
return;
errno = 0;
l = strtol(val, &end, 10);
if (errno || (end && *end))
return;
libinput_device_config_click_set_method(libinput_device,
(enum libinput_config_click_method)l);
}
static void
settap(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_TAP");
if (val) {
if (!val[0])
return;
libinput_device_config_tap_set_enabled(libinput_device,
isenabled(val, 1) ? LIBINPUT_CONFIG_TAP_ENABLED :
LIBINPUT_CONFIG_TAP_DISABLED);
} else if (tap_to_click && libinput_device_config_tap_get_finger_count(libinput_device))
libinput_device_config_tap_set_enabled(libinput_device,
LIBINPUT_CONFIG_TAP_ENABLED);
}
static void
settapanddrag(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_DRAG");
if (val && val[0])
libinput_device_config_tap_set_drag_enabled(libinput_device,
isenabled(val, 1) ? LIBINPUT_CONFIG_DRAG_ENABLED :
LIBINPUT_CONFIG_DRAG_DISABLED);
}
static void
setnaturalscroll(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_NATURAL_SCROLL");
if (val && val[0])
libinput_device_config_scroll_set_natural_scroll_enabled(
libinput_device, isenabled(val, 0));
else if (!val && libinput_device_config_scroll_has_natural_scroll(libinput_device))
libinput_device_config_scroll_set_natural_scroll_enabled(
libinput_device, natural_scrolling);
}
static void
setaccelprofile(struct libinput_device *libinput_device)
{
const char *val;
double profile;
char *end = NULL;
val = getenv("LIBINPUT_DEFAULT_ACCELERATION_PROFILE");
if (!val || !val[0])
return;
errno = 0;
profile = strtod(val, &end);
if (errno || (end && *end))
return;
libinput_device_config_accel_set_profile(libinput_device,
(enum libinput_config_accel_profile)profile);
}
static void
setaccelspeed(struct libinput_device *libinput_device)
{
const char *val;
double accel = 0;
char *end = NULL;
val = getenv("LIBINPUT_DEFAULT_ACCELERATION");
if (!val || !val[0])
return;
errno = 0;
accel = strtod(val, &end);
if (errno || (end && *end) || (accel < -1) || (accel > 1))
return;
libinput_device_config_accel_set_speed(libinput_device, accel);
}
static void
setscrollmethod(struct libinput_device *libinput_device)
{
const char *val;
long l;
char *end = NULL;
val = getenv("LIBINPUT_DEFAULT_SCROLL_METHOD");
if (!val || !val[0])
return;
errno = 0;
l = strtol(val, &end, 10);
if (errno || (end && *end))
return;
libinput_device_config_scroll_set_method(libinput_device,
(enum libinput_config_scroll_method)l);
}
static void
setdwt(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_DISABLE_WHILE_TYPING");
if (val && val[0])
libinput_device_config_dwt_set_enabled(libinput_device,
isenabled(val, false) ? LIBINPUT_CONFIG_DWT_ENABLED :
LIBINPUT_CONFIG_DWT_DISABLED);
}
static void
setmiddleemul(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_MIDDLE_EMULATION");
if (val && val[0])
libinput_device_config_middle_emulation_set_enabled(libinput_device,
isenabled(val, false) ? LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
}
static void
setlefthanded(struct libinput_device *libinput_device)
{
const char *val;
val = getenv("LIBINPUT_DEFAULT_LEFT_HANDED");
if (val && val[0])
libinput_device_config_left_handed_set(libinput_device,
isenabled(val, 0));
}
static void
inputconfig(struct libinput_device *libinput_device)
{
setclickmethod(libinput_device);
settap(libinput_device);
settapanddrag(libinput_device);
setnaturalscroll(libinput_device);
setaccelprofile(libinput_device);
setaccelspeed(libinput_device);
setscrollmethod(libinput_device);
setdwt(libinput_device);
setmiddleemul(libinput_device);
setlefthanded(libinput_device);
}
static void
parsecolor(const char *val, float color[4])
{
uint8_t r, g, b;
if (sscanf(val, "#%02hhx%02hhx%02hhx", &r, &g, &b) == 3) {
color[0] = (float)r / 0xFF;
color[1] = (float)g / 0xFF;
color[2] = (float)b / 0xFF;
color[3] = 1.0;
}
}
static void
loadtheme(void)
{
const char *val;
unsigned int tmp;
val = getenv("DWL_ROOT_COLOR");
if (val)
parsecolor(val, rootcolor);
val = getenv("DWL_BORDER_COLOR");
if (val)
parsecolor(val, bordercolor);
val = getenv("DWL_FOCUS_COLOR");
if (val)
parsecolor(val, focuscolor);
val = getenv("DWL_BORDER");
if (val && sscanf(val, "%u", &tmp) == 1)
borderpx = tmp;
}