コミットを比較

...

4 コミット

作成者 SHA1 メッセージ 日付
守矢諏訪子 f707d98ca8 要らない物の削除、FreeBSDの対応 2024-02-26 12:48:31 +09:00
守矢諏訪子 93dd63cbef ささ 2023-12-27 22:52:57 +09:00
守矢諏訪子 d5410a3826 背景を追加 2023-12-27 22:38:13 +09:00
守矢諏訪子 ea12c6abdc DPMSの設定機能性を追加 2023-12-27 21:03:59 +09:00
3個のファイルの変更418行の追加304行の削除

ファイルの表示

@ -6,15 +6,7 @@
#define TERMINAL "st"
#define TERMCLASS "St"
#if MYOS == ARTIX
#define BROWSER "iceweasel"
#elif MYOS == VOID || MYOS == OPENBSD || MYOS == FREEBSD
#define BROWSER "netsurf"
#elif MYOS == CRUX
#define BROWSER "librewolf"
#elif MYOS == POSTMARKETOS
#define BROWSER == "firefox-esr"
#endif
#define BROWSER "firefox-esr"
static const char wallpaper[] = "/home/suwako/.local/share/wallpapers/8ffe33a4a3459c39bcd0a11a528a3785-";
static const char ext[] = ".jpg";
@ -34,6 +26,15 @@ 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 */
@ -41,6 +42,8 @@ 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 */
@ -75,9 +78,11 @@ static Sp scratchpads[] = {
};
static const char *const autostart[] = {
"hsetroot", "-center", bgimg, NULL,
"xset", "-dpms", NULL,
"xset", "s", "off", NULL,
#if MYOS == OPENBSD
"uim", NULL,
#else
"fcitx5", NULL,
#endif
NULL /* terminate */
};

ファイルの表示

@ -4,49 +4,51 @@ OS := $(shell uname -s)
VERSION = 6.4
# paths
PREFIX = /usr
MANPREFIX = ${PREFIX}/share/man
ifeq ($(OS),FreeBSD)
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
else ifeq ($(OS),OpenBSD)
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/man
else
PREFIX = /usr
MANPREFIX = ${PREFIX}/share/man
endif
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
ifeq ($(OS),FreeBSD)
X11INC = /usr/local/include
X11LIB = /usr/local/lib
endif
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA
# freetype
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = ${PREFIX}/include/freetype2
ifeq ($(OS),OpenBSD)
FREETYPEINC = ${X11INC}/freetype2
else
FREETYPEINC = ${PREFIX}/include/freetype2
endif
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res -lXext -lImlib2 -lm -lXrandr
ifeq ($(OS),FreeBSD)
LIBS += -lutil
endif
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
ifeq ($(OS),Linux)
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
endif
ifeq ($(OS),OpenBSD)
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
endif
ifneq ($(OS),FreeBSD)
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
CPPFLAGS += -D_XOPEN_SOURCE=700L
else ifeq ($(OS),OpenBSD)
CPPFLAGS += -D_POSIX_C_SOURCE=200809L
else ifneq ($(OS),FreeBSD)
CPPFLAGS += -D_XOPEN_SOURCE=700L
endif
LDFLAGS = ${LIBS}
CFLAGS = ${INCS}
# compiler and linker
CC = cc

113
dwm.c
ファイルの表示

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <sys/types.h>
#include <sys/wait.h>
#if defined(__FreeBSD__)
@ -39,6 +40,7 @@
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <X11/XKBlib.h>
#include <X11/Xproto.h>
#include <X11/Xresource.h>
@ -47,6 +49,7 @@
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
#include <X11/extensions/dpms.h>
#include <X11/Xft/Xft.h>
#include <X11/Xlib-xcb.h>
#include <xcb/res.h>
@ -197,7 +200,9 @@ typedef struct {
} ResourcePref;
/* 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);
@ -393,6 +398,31 @@ autostart_exec() {
static pid_t *autostart_pids;
static size_t autostart_len;
void setdpms() {
Display *display;
int dummy;
display = XOpenDisplay(NULL);
if (!display) {
fprintf(stderr, "Xディスプレイを見つけられません。\n");
return;
}
if (!DPMSQueryExtension(display, &dummy, &dummy)) {
fprintf(stderr, "DPMSが対応していません。\n");
return;
}
DPMSEnable(display);
if (dpms == -1) {
DPMSDisable(display);
}
XSetScreenSaver(display, dpms, 0, DefaultBlanking, DefaultExposures);
XCloseDisplay(display);
}
/* 背景を設定 */
char bgimg[100];
@ -402,6 +432,81 @@ void setupbackgrounds() {
strcat(bgimg, ext);
}
void setrootbg() {
Pixmap pixmap;
Display *display;
Window wc;
int screen;
Imlib_Image image;
int screen_width, screen_height, screen_depth, 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);
screen_depth = DefaultDepth(display, screen);
pixmap = XCreatePixmap(display, wc, screen_width, screen_height, screen_depth);
// 画像を読み込む
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();
// https://gitlin.moe/himdel/hsetroot/blob/master/hsetroot.c
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)
@ -2449,9 +2554,9 @@ updatestatus(void)
Monitor* m;
if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) {
#if defined(__FreeBSD__) || defined(__OpenBSD__)
strlcpy(stext, "dwm-"VERSION, sizeof(stext));
strlcpy(stext, "dwm-6.4", sizeof(stext));
#else
strncpy(stext, "dwm-"VERSION, sizeof(stext) - 1);
strncpy(stext, "dwm-6.4", sizeof(stext) - 1);
stext[sizeof(stext) - 1] = '\0';
#endif
} else {
@ -2778,7 +2883,7 @@ int
main(int argc, char *argv[])
{
if (argc == 2 && !strcmp("-v", argv[1]))
die("dwm-"VERSION);
die("dwm-6.4");
else if (argc != 1)
die("usage: dwm [-v]");
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
@ -2788,7 +2893,9 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
setdpms();
setupbackgrounds();
setrootbg();
autostart_exec();
XrmInitialize();
load_xresources();