Skip to content

Commit

Permalink
patch mainlayout and modify default window settings
Browse files Browse the repository at this point in the history
  • Loading branch information
GarytheNoob committed Jul 20, 2023
1 parent 6f7316b commit 8d3e948
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 25 deletions.
24 changes: 14 additions & 10 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char autostartCmd[] ="sh /home/GarytheNoob/workspace/dwm-build/scripts/autostart.sh";
static const char autostartCmd[] ="sh /home/GarytheNoob/workspace/dwm-build/scripts/autostart.sh"; /* the autostart command */
static const unsigned int baralpha = 0xd0;
static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3] = {
Expand All @@ -43,11 +43,13 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
/* class instance title tags mask isfloating focusopacity unfocusopacity monitor */
{ "Gimp", NULL, NULL, 0, 1, 1.0, inactiveopacity, -1 },
{ "Firefox", NULL, NULL, 1 << 1, 0, 1.0, activeopacity, -1 },
{ "firefox", NULL, NULL, 1 << 1, 0, 1.0, activeopacity, -1 },
{ "QQ", NULL, NULL, 1 << 2, 0, 1.0, inactiveopacity, -1 },
/* class instance title tags mask isfloating focusopacity unfocusopacity monitor */
{ "Gimp", NULL, NULL, 0, 1, 1.0, inactiveopacity, -1 },
{ NULL, NULL, "图片查看器", 0, 1, 1.0, inactiveopacity, -1 },
{ NULL, NULL, "图片查看", 0, 1, 1.0, inactiveopacity, -1 },
{ "Firefox", NULL, NULL, 1 << 1, 0, 1.0, activeopacity, -1 },
{ "firefox", NULL, NULL, 1 << 1, 0, 1.0, activeopacity, -1 },
{ "QQ", NULL, NULL, 1 << 2, 0, 1.0, inactiveopacity, -1 },
};

/* layout(s) */
Expand All @@ -61,8 +63,9 @@ static const Layout layouts[] = {
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
{ "+++", grid},
{ "===", magicgrid},
{ "|M|", centeredmaster },
{ ">M>", centeredfloatingmaster },
};

/* key definitions */
Expand Down Expand Up @@ -117,14 +120,15 @@ static const Key keys[] = {
{ MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } },
{ MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } },
{ MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY|ShiftMask, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY|ShiftMask, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY|ShiftMask, XK_m, setlayout, {.v = &layouts[2]} },
/* { MODKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[3]} },*/
{ MODKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[4]} },
{ MODKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[3]} },
{ MODKEY|ShiftMask, XK_u, setlayout, {.v = &layouts[4]} },
{ MODKEY|ShiftMask, XK_o, setlayout, {.v = &layouts[5]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
Expand Down
Binary file modified dwm
Binary file not shown.
105 changes: 105 additions & 0 deletions dwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xinitvisual();
static void zoom(const Arg *arg);
static void centeredmaster(Monitor *m);
static void centeredfloatingmaster(Monitor *m);

/* variables */
static const char broken[] = "broken";
Expand Down Expand Up @@ -2740,3 +2742,106 @@ main(int argc, char *argv[])
XCloseDisplay(dpy);
return EXIT_SUCCESS;
}

void
centeredmaster(Monitor *m)
{
unsigned int i, n, h, mw, mx, my, oty, ety, tw;
Client *c;

/* count number of clients in the selected monitor */
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;

/* initialize areas */
mw = m->ww;
mx = 0;
my = 0;
tw = mw;

if (n > m->nmaster) {
/* go mfact box in the center if more than nmaster clients */
mw = m->nmaster ? m->ww * m->mfact : 0;
tw = m->ww - mw;

if (n - m->nmaster > 1) {
/* only one client */
mx = (m->ww - mw) / 2;
tw = (m->ww - mw) / 2;
}
}

oty = 0;
ety = 0;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
/* nmaster clients are stacked vertically, in the center
* of the screen */
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw),
h - (2*c->bw), 0);
my += HEIGHT(c);
} else {
/* stack clients are stacked vertically */
if ((i - m->nmaster) % 2 ) {
h = (m->wh - ety) / ( (1 + n - i) / 2);
resize(c, m->wx, m->wy + ety, tw - (2*c->bw),
h - (2*c->bw), 0);
ety += HEIGHT(c);
} else {
h = (m->wh - oty) / ((1 + n - i) / 2);
resize(c, m->wx + mx + mw, m->wy + oty,
tw - (2*c->bw), h - (2*c->bw), 0);
oty += HEIGHT(c);
}
}
}

void
centeredfloatingmaster(Monitor *m)
{
unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx;
Client *c;

/* count number of clients in the selected monitor */
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;

/* initialize nmaster area */
if (n > m->nmaster) {
/* go mfact box in the center if more than nmaster clients */
if (m->ww > m->wh) {
mw = m->nmaster ? m->ww * m->mfact : 0;
mh = m->nmaster ? m->wh * 0.9 : 0;
} else {
mh = m->nmaster ? m->wh * m->mfact : 0;
mw = m->nmaster ? m->ww * 0.9 : 0;
}
mx = mxo = (m->ww - mw) / 2;
my = myo = (m->wh - mh) / 2;
} else {
/* go fullscreen if all clients are in the master area */
mh = m->wh;
mw = m->ww;
mx = mxo = 0;
my = myo = 0;
}

for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
/* nmaster clients are stacked horizontally, in the center
* of the screen */
w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i);
resize(c, m->wx + mx, m->wy + my, w - (2*c->bw),
mh - (2*c->bw), 0);
mx += WIDTH(c);
} else {
/* stack clients are stacked horizontally */
w = (m->ww - tx) / (n - i);
resize(c, m->wx + tx, m->wy, w - (2*c->bw),
m->wh - (2*c->bw), 0);
tx += WIDTH(c);
}
}
2 changes: 1 addition & 1 deletion scripts/autostart.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/xrandrInit.sh
# /bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/dwmInit.sh
/bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/dwmInit.sh
/bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/clashInit.sh
/bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/picom.sh
/bin/bash /home/GarytheNoob/workspace/dwm-build/scripts/wallpaper.sh
Expand Down
1 change: 0 additions & 1 deletion scripts/clashInit.sh

This file was deleted.

14 changes: 3 additions & 11 deletions scripts/dwmInit.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:en_US
export LC_CTYPE=en_US.UTF-8

export GTK_IM_MODULE DEFAULT=fcitx
export QT_IM_MODULE DEFAULT=fcitx
export XMODIFIERS DEFAULT=\@im=fcitx

exec dwmblocks &
exec fcitx &
exec dunst &
picom &
sxhkd &
clash-verge &
1 change: 0 additions & 1 deletion scripts/picom.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/xrandrInit.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# 使用 xrandr 命令获取连接的显示器信息,并提取 eDP 和 HDMI 显示器名称 connected_displays=$(xrandr | grep " connected" | awk '{print $1}') edp_display=""
# 使用 xrandr 命令获取连接的显示器信息,并提取 eDP 和 HDMI 显示器名称
connected_displays=$(xrandr | grep " connected" | awk '{print $1}')
hdmi_display=""

Expand Down

0 comments on commit 8d3e948

Please sign in to comment.