Xrandr

如何配置多個監視器以使用 dwm 的標記規則?

  • December 19, 2017

我有一台帶外接顯示器的筆記型電腦,我想將外接顯示器用作主要顯示器。我也在用 dwm 執行 Debian。xrandr -q給了我這個:

Screen 0: minimum 320 x 200, current 3286 x 1080, maximum 8192 x 8192
LVDS1 connected 1366x768+1920+0 (normal left inverted right x axis y axis) 345mm x 194mm
  1366x768       60.0*+   50.0
VGA1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 509mm x 286mm
  1920x1080      60.0*+

(為簡潔起見,我省略了其他一些決議)。我的 dwm config.h 文件有幾個標籤規則,如下所示:

static const Rule rules[] = {
   /* xprop(1):
    *  WM_CLASS(STRING) = instance, class
    *  WM_NAME(STRING) = title
    */
   /* class      instance    title       tags mask     isfloating   monitor */
   { "Chromium",    NULL,   NULL,       1,            False,       -1 },
   { "xxxterm",     NULL,   NULL,       1,            False,       -1 },
   { "Surf",        NULL,   NULL,       1,            False,       -1 },
   { "Iceweasel",   NULL,   NULL,       1 << 1,       False,       -1 },
   { "Vlc",         NULL,   NULL,       1 << 3,       False,       -1 },
};

我的 ~/.xinitrc 文件中有這個 xrandr 命令,可以在我執行時正確配置監視器startx

xrandr --output VGA1 --auto --output LVDS1 --auto --right-of VGA1

我希望我的標籤規則在我打開程序時應用,並且該程序自動分配給具有焦點的任何監視器。我發現一個reddit 文章說 -1 會這樣做,但是對於任何具​​有標記規則的程序,它們總是在我的筆記型電腦 (LVDS1) 上打開,而不是在外接顯示器 (VGA1) 上打開。

對於沒有標籤規則的程序,例如 st,它們將在具有焦點的任何監視器/標籤上打開。我嘗試將monitor值改為0或1,重建dwm並重新啟動X,結果是一樣的。

如何配置 dwm 以便具有標籤規則的程序在其各自的標籤中打開,無論哪個監視器都有焦點?


我的完整config.h

/* appearance */
static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#333333";
static const char normbgcolor[]     = "#101010";
static const char normfgcolor[]     = "#999999";
static const char selbordercolor[]  = "#224488";
static const char selbgcolor[]      = "#224488";
static const char selfgcolor[]      = "#ffffff";
static const unsigned int borderpx  = 1;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const unsigned int minwsz    = 20;       /* Minimal heigt of a client */
static const Bool showbar           = True;     /* False means no bar */
static const Bool topbar            = True;     /* False means bottom bar */
static const Bool viewontag         = False;    /* Switch view on tag switch */
static const Bool extrabar          = True;     /* False means no extra bar */

/* tagging */
static const char *tags[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9" };

static const Rule rules[] = {
   /* xprop(1):
    *  WM_CLASS(STRING) = instance, class
    *  WM_NAME(STRING) = title
    */
   /* class      instance    title       tags mask     isfloating   monitor */
   { "Chromium",    NULL,   NULL,       1,            False,       -1 },
   { "xxxterm",     NULL,   NULL,       1,            False,       -1 },
   { "Surf",        NULL,   NULL,       1,            False,       -1 },
   { "Iceweasel",   NULL,   NULL,       1 << 1,       False,       -1 },
   { "Vlc",         NULL,   NULL,       1 << 3,       False,       -1 },
   { NULL,          NULL,   "IPython",  1 << 4,       False,       -1 },
   { "Eclipse",     NULL,   NULL,       1 << 4,       False,       -1 },
   { "Quodlibet",   NULL,   NULL,       1 << 5,       False,       -1 },
   { "Icedove",     NULL,   NULL,       1 << 6,       False,       -1 },
   { "libreoffice", NULL,   NULL,       1 << 7,       False,       -1 },
   { "Gnumeric",    NULL,   NULL,       1 << 7,       False,       -1 },
   { "Abiword",     NULL,   NULL,       1 << 7,       False,       -1 },
   { "Keepassx",    NULL,   NULL,       1 << 8,       False,       -1 },
};

/* layout(s) */
static const float mfact      = 0.50; /* factor of master area size [0.05..0.95] */
static const float smfact     = 0.00; /* factor of tiled clients [0.00..0.95] */
static const int nmaster      = 1;    /* number of clients in master area */
static const Bool resizehints = False; /* True means respect size hints in tiled resizals */

#include "patchlibs/bstack.c"
#include "patchlibs/bstackhoriz.c"
#include "patchlibs/fibonacci.c"
#include "patchlibs/gaplessgrid.c"
#include "patchlibs/tcl.c"
static const Layout layouts[] = {
   /* symbol     arrange function */
   { "T",      tile },    /* first entry is default */
   { "F",      NULL },    /* no layout function means floating behavior */
   { "B",      bstack },
   { "G",      gaplessgrid },
   { "M",      monocle },
   { "H",      bstackhoriz },
   { "C",      tcl },
   { "S",      spiral },
   { "D",      dwindle },
};

/* key definitions */
#define MODKEY Mod1Mask
#define WINKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
   { MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
   { MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
   { MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
   { MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[]  = { "st", NULL };
static const char *chromiumcmd[] = {"chromium-incognito", NULL};
static const char *icedovecmd[] = {"icedove", NULL};
static const char *xxxtermcmd[] = {"xxxterm", NULL};
static const char *musiccmd[] = {"quodlibet", NULL};
static const char *ipythoncmd[] = {"ipython3qt", NULL};
static const char *iceweaselcmd[] = {"iceweasel", NULL};
static const char *texteditcmd[] = {"scite", NULL};
static const char *lockcmd[] = {"lock", NULL};
static const char *videocmd[] = {"vlc", NULL};
static const char *screenshotcmd[] = {"screenshot", NULL};

#include "patchlibs/movestack.c"
static Key keys[] = {
   /* modifier                     key        function        argument */
   { WINKEY,                       XK_t,      spawn,          {.v = termcmd } },
   { WINKEY,                       XK_c,      spawn,          {.v = chromiumcmd } },
   { WINKEY,                       XK_d,      spawn,          {.v = icedovecmd } },
   { WINKEY,                       XK_x,      spawn,          {.v = xxxtermcmd } },
   { WINKEY,                       XK_i,      spawn,          {.v = iceweaselcmd } },
   { WINKEY,                       XK_m,      spawn,          {.v = musiccmd } },
   { WINKEY,                       XK_e,      spawn,          {.v = texteditcmd } },
   { WINKEY,                       XK_p,      spawn,          {.v = ipythoncmd } },
   { WINKEY,                       XK_l,      spawn,          {.v = lockcmd } },
   { WINKEY,                       XK_v,      spawn,          {.v = videocmd } },
   { WINKEY,                       XK_s,      spawn,          {.v = screenshotcmd } },
   { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
   { MODKEY,                       XK_b,      togglebar,      {0} },
   { MODKEY,                       XK_b,      toggleextrabar,      {0} },
   { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
   { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
   { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
   { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
   { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
   { MODKEY,                       XK_u,      setsmfact,      {.f = -0.05} },
   { MODKEY,                       XK_m,      setsmfact,      {.f = +0.05} },
   { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
   { MODKEY,                       XK_Return, zoom,           {0} },
   { MODKEY,                       XK_Tab,    view,           {0} },
   { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
   { ControlMask|ShiftMask,        XK_t,      setlayout,      {.v = &layouts[0]} },
   { ControlMask|ShiftMask,        XK_f,      setlayout,      {.v = &layouts[1]} },
   { ControlMask|ShiftMask,        XK_b,      setlayout,      {.v = &layouts[2]} },
   { ControlMask|ShiftMask,        XK_g,      setlayout,      {.v = &layouts[3]} },
   { ControlMask|ShiftMask,        XK_m,      setlayout,      {.v = &layouts[4]} },
   { ControlMask|ShiftMask,        XK_h,      setlayout,      {.v = &layouts[5]} },
   { ControlMask|ShiftMask,        XK_c,      setlayout,      {.v = &layouts[6]} },
   { ControlMask|ShiftMask,        XK_s,      setlayout,      {.v = &layouts[7]} },
   { ControlMask|ShiftMask,        XK_d,      setlayout,      {.v = &layouts[8]} },
   { ControlMask,                  XK_space,  setlayout,      {0} },
   { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
   { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
   { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
   { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
   { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
   { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
   { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
   { MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } },
   { MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } },
   TAGKEYS(                        XK_1,                      0)
   TAGKEYS(                        XK_2,                      1)
   TAGKEYS(                        XK_3,                      2)
   TAGKEYS(                        XK_4,                      3)
   TAGKEYS(                        XK_5,                      4)
   TAGKEYS(                        XK_6,                      5)
   TAGKEYS(                        XK_7,                      6)
   TAGKEYS(                        XK_8,                      7)
   TAGKEYS(                        XK_9,                      8)
   { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
   /* click                event mask      button          function        argument */
   { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
   { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[3]} },
   { ClkWinTitle,          0,              Button2,        zoom,           {0} },
   { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
   { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
   { ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
   { ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
   { ClkTagBar,            0,              Button1,        view,           {0} },
   { ClkTagBar,            0,              Button3,        toggleview,     {0} },
   { ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
   { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
};

預設的 dwm 行為是在具有焦點的監視器/螢幕上打開應用程序,無論是否有規則。

要在目前關注的監視器的第三個標籤上打開 Surf,規則是:

  { "Surf",       NULL,       NULL,       1 << 2,       True,        -1 },

要在主監視器的第二個標籤上打開 VLC,無論焦點在哪裡,規則是:

  { "VLC",       NULL,       NULL,       1 << 1,       True,        1 },

如果您的規則不符合此行為,那麼您配置 dwm 的方式可能存在其他問題。粘貼你的整個config.h可能會有所幫助。

引用自:https://unix.stackexchange.com/questions/120972