aboutsummaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-23 14:16:52 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:56:26 -0600
commit05c66cb37d9ff278a3e0c45682c4b5e7945deb42 (patch)
tree273ee88089e86784a261c5564dd51e9489bcd09e /x.c
parent33201ac65f74e45b4fa60822ba9a538c3cfa9b25 (diff)
downloadst-05c66cb37d9ff278a3e0c45682c4b5e7945deb42.tar.gz
st-05c66cb37d9ff278a3e0c45682c4b5e7945deb42.zip
Split mode bits between Term and TermWindow
Moves the mode bits used by x.c from Term to TermWindow, absorbing UI/input-related mode bits (visible/focused/numlock) along the way. This is gradually reducing external references to Term. Since TermWindow is already internal to x.c, we add xsetmode() to allow st to modify window bits in accordance with escape sequences. IS_SET() is redefined accordingly (term.mode in st.c, win.mode in x.c). Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
Diffstat (limited to 'x.c')
-rw-r--r--x.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/x.c b/x.c
index 76fb910..c5826cf 100644
--- a/x.c
+++ b/x.c
@@ -51,6 +51,7 @@ typedef struct {
51/* function definitions used in config.h */ 51/* function definitions used in config.h */
52static void clipcopy(const Arg *); 52static void clipcopy(const Arg *);
53static void clippaste(const Arg *); 53static void clippaste(const Arg *);
54static void numlock(const Arg *);
54static void selpaste(const Arg *); 55static void selpaste(const Arg *);
55static void zoom(const Arg *); 56static void zoom(const Arg *);
56static void zoomabs(const Arg *); 57static void zoomabs(const Arg *);
@@ -64,6 +65,7 @@ static void zoomreset(const Arg *);
64#define XEMBED_FOCUS_OUT 5 65#define XEMBED_FOCUS_OUT 5
65 66
66/* macros */ 67/* macros */
68#define IS_SET(flag) ((win.mode & (flag)) != 0)
67#define TRUERED(x) (((x) & 0xff0000) >> 8) 69#define TRUERED(x) (((x) & 0xff0000) >> 8)
68#define TRUEGREEN(x) (((x) & 0xff00)) 70#define TRUEGREEN(x) (((x) & 0xff00))
69#define TRUEBLUE(x) (((x) & 0xff) << 8) 71#define TRUEBLUE(x) (((x) & 0xff) << 8)
@@ -196,11 +198,6 @@ static XWindow xw;
196static XSelection xsel; 198static XSelection xsel;
197static TermWindow win; 199static TermWindow win;
198 200
199enum window_state {
200 WIN_VISIBLE = 1,
201 WIN_FOCUSED = 2
202};
203
204/* Font Ring Cache */ 201/* Font Ring Cache */
205enum { 202enum {
206 FRC_NORMAL, 203 FRC_NORMAL,
@@ -264,6 +261,12 @@ selpaste(const Arg *dummy)
264} 261}
265 262
266void 263void
264numlock(const Arg *dummy)
265{
266 win.mode ^= MODE_NUMLOCK;
267}
268
269void
267zoom(const Arg *arg) 270zoom(const Arg *arg)
268{ 271{
269 Arg larg; 272 Arg larg;
@@ -1090,6 +1093,7 @@ xinit(void)
1090 XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32, 1093 XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
1091 PropModeReplace, (uchar *)&thispid, 1); 1094 PropModeReplace, (uchar *)&thispid, 1);
1092 1095
1096 win.mode = MODE_NUMLOCK;
1093 resettitle(); 1097 resettitle();
1094 XMapWindow(xw.dpy, xw.win); 1098 XMapWindow(xw.dpy, xw.win);
1095 xhints(); 1099 xhints();
@@ -1319,14 +1323,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
1319 fg = &revfg; 1323 fg = &revfg;
1320 } 1324 }
1321 1325
1322
1323 if (base.mode & ATTR_REVERSE) { 1326 if (base.mode & ATTR_REVERSE) {
1324 temp = fg; 1327 temp = fg;
1325 fg = bg; 1328 fg = bg;
1326 bg = temp; 1329 bg = temp;
1327 } 1330 }
1328 1331
1329 if (base.mode & ATTR_BLINK && term.mode & MODE_BLINK) 1332 if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
1330 fg = bg; 1333 fg = bg;
1331 1334
1332 if (base.mode & ATTR_INVISIBLE) 1335 if (base.mode & ATTR_INVISIBLE)
@@ -1440,7 +1443,7 @@ xdrawcursor(void)
1440 return; 1443 return;
1441 1444
1442 /* draw the new one */ 1445 /* draw the new one */
1443 if (win.state & WIN_FOCUSED) { 1446 if (IS_SET(MODE_FOCUSED)) {
1444 switch (win.cursor) { 1447 switch (win.cursor) {
1445 case 7: /* st extension: snowman */ 1448 case 7: /* st extension: snowman */
1446 utf8decode("☃", &g.u, UTF_SIZ); 1449 utf8decode("☃", &g.u, UTF_SIZ);
@@ -1527,7 +1530,7 @@ drawregion(int x1, int y1, int x2, int y2)
1527 Glyph base, new; 1530 Glyph base, new;
1528 XftGlyphFontSpec *specs; 1531 XftGlyphFontSpec *specs;
1529 1532
1530 if (!(win.state & WIN_VISIBLE)) 1533 if (!(IS_SET(MODE_VISIBLE)))
1531 return; 1534 return;
1532 1535
1533 for (y = y1; y < y2; y++) { 1536 for (y = y1; y < y2; y++) {
@@ -1575,13 +1578,13 @@ visibility(XEvent *ev)
1575{ 1578{
1576 XVisibilityEvent *e = &ev->xvisibility; 1579 XVisibilityEvent *e = &ev->xvisibility;
1577 1580
1578 MODBIT(win.state, e->state != VisibilityFullyObscured, WIN_VISIBLE); 1581 MODBIT(win.mode, e->state != VisibilityFullyObscured, MODE_VISIBLE);
1579} 1582}
1580 1583
1581void 1584void
1582unmap(XEvent *ev) 1585unmap(XEvent *ev)
1583{ 1586{
1584 win.state &= ~WIN_VISIBLE; 1587 win.mode &= ~MODE_VISIBLE;
1585} 1588}
1586 1589
1587void 1590void
@@ -1591,6 +1594,15 @@ xsetpointermotion(int set)
1591 XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs); 1594 XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
1592} 1595}
1593 1596
1597void
1598xsetmode(int set, unsigned int flags)
1599{
1600 int mode = win.mode;
1601 MODBIT(win.mode, set, flags);
1602 if ((win.mode & MODE_REVERSE) != (mode & MODE_REVERSE))
1603 redraw();
1604}
1605
1594int 1606int
1595xsetcursor(int cursor) 1607xsetcursor(int cursor)
1596{ 1608{
@@ -1614,7 +1626,7 @@ xseturgency(int add)
1614void 1626void
1615xbell(void) 1627xbell(void)
1616{ 1628{
1617 if (!(win.state & WIN_FOCUSED)) 1629 if (!(IS_SET(MODE_FOCUSED)))
1618 xseturgency(1); 1630 xseturgency(1);
1619 if (bellvolume) 1631 if (bellvolume)
1620 XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL); 1632 XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
@@ -1630,13 +1642,13 @@ focus(XEvent *ev)
1630 1642
1631 if (ev->type == FocusIn) { 1643 if (ev->type == FocusIn) {
1632 XSetICFocus(xw.xic); 1644 XSetICFocus(xw.xic);
1633 win.state |= WIN_FOCUSED; 1645 win.mode |= MODE_FOCUSED;
1634 xseturgency(0); 1646 xseturgency(0);
1635 if (IS_SET(MODE_FOCUS)) 1647 if (IS_SET(MODE_FOCUS))
1636 ttywrite("\033[I", 3, 0); 1648 ttywrite("\033[I", 3, 0);
1637 } else { 1649 } else {
1638 XUnsetICFocus(xw.xic); 1650 XUnsetICFocus(xw.xic);
1639 win.state &= ~WIN_FOCUSED; 1651 win.mode &= ~MODE_FOCUSED;
1640 if (IS_SET(MODE_FOCUS)) 1652 if (IS_SET(MODE_FOCUS))
1641 ttywrite("\033[O", 3, 0); 1653 ttywrite("\033[O", 3, 0);
1642 } 1654 }
@@ -1673,7 +1685,7 @@ kmap(KeySym k, uint state)
1673 1685
1674 if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0) 1686 if (IS_SET(MODE_APPKEYPAD) ? kp->appkey < 0 : kp->appkey > 0)
1675 continue; 1687 continue;
1676 if (term.numlock && kp->appkey == 2) 1688 if (IS_SET(MODE_NUMLOCK) && kp->appkey == 2)
1677 continue; 1689 continue;
1678 1690
1679 if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0) 1691 if (IS_SET(MODE_APPCURSOR) ? kp->appcursor < 0 : kp->appcursor > 0)
@@ -1742,10 +1754,10 @@ cmessage(XEvent *e)
1742 */ 1754 */
1743 if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) { 1755 if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
1744 if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) { 1756 if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
1745 win.state |= WIN_FOCUSED; 1757 win.mode |= MODE_FOCUSED;
1746 xseturgency(0); 1758 xseturgency(0);
1747 } else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) { 1759 } else if (e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
1748 win.state &= ~WIN_FOCUSED; 1760 win.mode &= ~MODE_FOCUSED;
1749 } 1761 }
1750 } else if (e->xclient.data.l[0] == xw.wmdeletewin) { 1762 } else if (e->xclient.data.l[0] == xw.wmdeletewin) {
1751 /* Send SIGHUP to shell */ 1763 /* Send SIGHUP to shell */
@@ -1810,7 +1822,7 @@ run(void)
1810 if (blinktimeout) { 1822 if (blinktimeout) {
1811 blinkset = tattrset(ATTR_BLINK); 1823 blinkset = tattrset(ATTR_BLINK);
1812 if (!blinkset) 1824 if (!blinkset)
1813 MODBIT(term.mode, 0, MODE_BLINK); 1825 MODBIT(win.mode, 0, MODE_BLINK);
1814 } 1826 }
1815 } 1827 }
1816 1828
@@ -1825,7 +1837,7 @@ run(void)
1825 dodraw = 0; 1837 dodraw = 0;
1826 if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) { 1838 if (blinktimeout && TIMEDIFF(now, lastblink) > blinktimeout) {
1827 tsetdirtattr(ATTR_BLINK); 1839 tsetdirtattr(ATTR_BLINK);
1828 term.mode ^= MODE_BLINK; 1840 win.mode ^= MODE_BLINK;
1829 lastblink = now; 1841 lastblink = now;
1830 dodraw = 1; 1842 dodraw = 1;
1831 } 1843 }