From d5410a382643daee92f5d65e8506c1949d7f30b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 27 Dec 2023 22:38:13 +0900 Subject: [PATCH] =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.h | 76 ++++++++++++++++++++++++++++------------------- config.mk | 2 +- dwm.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 35 deletions(-) diff --git a/config.h b/config.h index a85f13b..a21308a 100644 --- a/config.h +++ b/config.h @@ -34,18 +34,28 @@ static const char resolution[] = "1050"; static const char resolution[] = "1280"; #endif +typedef enum { + MODE_CENTER, + MODE_COVER, + MODE_TILE, + MODE_FULL, + /* MODE_EXTEND, */ + MODE_FILL +} BGMode; + /* appearance */ -static unsigned int borderpx = 3; /* border pixel of windows */ -static unsigned int snap = 32; /* snap pixel */ -static unsigned int gappih = 5; /* horiz inner gap between windows */ -static unsigned int gappiv = 5; /* vert inner gap between windows */ -static unsigned int gappoh = 5; /* horiz outer gap between windows and screen edge */ -static unsigned int gappov = 5; /* vert outer gap between windows and screen edge */ -static unsigned int dpms = -1; /* 分間。DPMSを無効にする場合:-1 */ -static int swallowfloating = 0; /* 1 means swallow floating windows by default */ -static int smartgaps = 0; /* 1 means no outer gap when there is only one window */ -static int showbar = 1; /* 0 means no bar */ -static int topbar = 1; /* 0 means bottom bar */ +static unsigned int borderpx = 3; /* border pixel of windows */ +static unsigned int snap = 32; /* snap pixel */ +static unsigned int gappih = 5; /* horiz inner gap between windows */ +static unsigned int gappiv = 5; /* vert inner gap between windows */ +static unsigned int gappoh = 5; /* horiz outer gap between windows and screen edge */ +static unsigned int gappov = 5; /* vert outer gap between windows and screen edge */ +static unsigned int dpms = -1; /* 秒間。DPMSを無効にする場合:-1 */ +static BGMode bgmode = MODE_FILL; /* 背景モード */ +static int swallowfloating = 0; /* 1 means swallow floating windows by default */ +static int smartgaps = 0; /* 1 means no outer gap when there is only one window */ +static int showbar = 1; /* 0 means no bar */ +static int topbar = 1; /* 0 means bottom bar */ #if MYPC == DESKTOP || MYPC == T43 static char *fonts[] = { "monospace:size=10", "NotoColorEmoji:pixelsize=10:antialias=true:autohint=true" }; #else @@ -76,7 +86,11 @@ static Sp scratchpads[] = { }; static const char *const autostart[] = { - "hsetroot", "-center", bgimg, NULL, +#if MYOS == OPENBSD + "uim", NULL, +#else + "fcitx5", NULL, +#endif NULL /* terminate */ }; @@ -158,25 +172,25 @@ static const char *termcmd[] = { TERMINAL, NULL }; * Xresources preferences to load at startup */ ResourcePref resources[] = { - { "color0", STRING, &normbordercolor }, - { "color8", STRING, &selbordercolor }, - { "color0", STRING, &normbgcolor }, - { "color4", STRING, &normfgcolor }, - { "color0", STRING, &selfgcolor }, - { "color4", STRING, &selbgcolor }, - { "borderpx", INTEGER, &borderpx }, - { "snap", INTEGER, &snap }, - { "showbar", INTEGER, &showbar }, - { "topbar", INTEGER, &topbar }, - { "nmaster", INTEGER, &nmaster }, - { "resizehints", INTEGER, &resizehints }, - { "mfact", FLOAT, &mfact }, - { "gappih", INTEGER, &gappih }, - { "gappiv", INTEGER, &gappiv }, - { "gappoh", INTEGER, &gappoh }, - { "gappov", INTEGER, &gappov }, - { "swallowfloating", INTEGER, &swallowfloating }, - { "smartgaps", INTEGER, &smartgaps }, + { "color0", STRING, &normbordercolor }, + { "color8", STRING, &selbordercolor }, + { "color0", STRING, &normbgcolor }, + { "color4", STRING, &normfgcolor }, + { "color0", STRING, &selfgcolor }, + { "color4", STRING, &selbgcolor }, + { "borderpx", INTEGER, &borderpx }, + { "snap", INTEGER, &snap }, + { "showbar", INTEGER, &showbar }, + { "topbar", INTEGER, &topbar }, + { "nmaster", INTEGER, &nmaster }, + { "resizehints", INTEGER, &resizehints }, + { "mfact", FLOAT, &mfact }, + { "gappih", INTEGER, &gappih }, + { "gappiv", INTEGER, &gappiv }, + { "gappoh", INTEGER, &gappoh }, + { "gappov", INTEGER, &gappov }, + { "swallowfloating", INTEGER, &swallowfloating }, + { "smartgaps", INTEGER, &smartgaps }, }; #include diff --git a/config.mk b/config.mk index 2e9af21..d898530 100644 --- a/config.mk +++ b/config.mk @@ -31,7 +31,7 @@ endif # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res -lXext +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res -lXext -lImlib2 -lm ifeq ($(OS),FreeBSD) LIBS += -lutil endif diff --git a/dwm.c b/dwm.c index 6d97dd7..898e3b7 100644 --- a/dwm.c +++ b/dwm.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #if defined(__FreeBSD__) @@ -39,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +202,7 @@ typedef struct { /* function declarations */ static void setdpms(); static void setupbackgrounds(); +static void setrootbg(); static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); static void arrange(Monitor *m); @@ -395,9 +398,6 @@ autostart_exec() { static pid_t *autostart_pids; static size_t autostart_len; -/* 背景を設定 */ -char bgimg[100]; - void setdpms() { Display *display; int dummy; @@ -423,12 +423,94 @@ void setdpms() { XCloseDisplay(display); } +/* 背景を設定 */ +char bgimg[100]; + void setupbackgrounds() { strcpy(bgimg, wallpaper); strcat(bgimg, resolution); strcat(bgimg, ext); } +void setrootbg() { + Pixmap pixmap; + Display *display; + Window wc; + int screen; + Imlib_Image image; + int screen_width, screen_height, image_width, image_height; + float scale; + + display = XOpenDisplay(NULL); + if (!display) { + fprintf(stderr, "エラー: ディスプレイに接続できません。\n"); + return; + } + + wc = DefaultRootWindow(display); + + screen = DefaultScreen(display); + screen_width = DisplayWidth(display, screen); + screen_height = DisplayHeight(display, screen); + pixmap = XCreatePixmap( + display, + wc, + DisplayWidth(display, screen), + DisplayHeight(display, screen), + DefaultDepth(display, screen) + ); + + // 画像を読み込む + imlib_context_set_display(display); + imlib_context_set_visual(DefaultVisual(display, screen)); + imlib_context_set_colormap(DefaultColormap(display, screen)); + imlib_context_set_drawable(pixmap); + + image = imlib_load_image(bgimg); + if (!image) { + fprintf(stderr, "画像の読み込みに失敗:%s\n", bgimg); + return; + } + + imlib_context_set_image(image); + image_width = imlib_image_get_width(); + image_height = imlib_image_get_height(); + + switch (bgmode) { + case MODE_CENTER: + imlib_render_image_on_drawable((screen_width - image_width) / 2, (screen_height - image_height) / 2); + break; + case MODE_COVER: + scale = fmax((float)screen_width / image_width, (float)screen_height / image_height); + imlib_render_image_on_drawable_at_size((screen_width - (int)(image_width * scale)) / 2, (screen_height - (int)(image_height * scale)) / 2, (int)(image_width * scale), (int)(image_height * scale)); + break; + case MODE_TILE: + for (int x = 0; x < screen_width; x += image_width) { + for (int y = 0; y < screen_height; y += image_height) { + imlib_render_image_on_drawable(x, y); + } + } + break; + case MODE_FULL: + imlib_render_image_on_drawable_at_size(0, 0, screen_width, screen_height); + break; + /* case MODE_EXTEND: */ + /* // 現在は未対応 */ + /* break; */ + case MODE_FILL: + scale = fmax((float)screen_width / image_width, (float)screen_height / image_height); + imlib_render_image_on_drawable_at_size(0, 0, (int)(image_width * scale), (int)(image_height * scale)); + default: + break; + } + + imlib_free_image(); + XSetWindowBackgroundPixmap(display, wc, pixmap); + XFreePixmap(display, pixmap); + XClearWindow(display, wc); + XCloseDisplay(display); +} + /* function implementations */ void applyrules(Client *c) @@ -2817,6 +2899,7 @@ main(int argc, char *argv[]) checkotherwm(); setdpms(); setupbackgrounds(); + setrootbg(); autostart_exec(); XrmInitialize(); load_xresources();