]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 12 Apr 2018 01:46:04 +0000 (21:46 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 12 Apr 2018 01:46:04 +0000 (21:46 -0400)
inc/win.h
lib/x11.c

index e995b2b2c55e3b9ee1679c04343e8b84d22e089e..c7573b15fac8ac0f997a32bc0fc8f9fa9938a7cb 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -142,7 +142,6 @@ void win_loop(void);
 void win_quit(void);
 View* win_view(WinRegion id);
 Buf* win_buf(WinRegion id);
-//bool win_btnpressed(int btn);
 WinRegion win_getregion(void);
 void win_setregion(WinRegion id);
 
index d125805cf2c988c45cdda119b4f22720cb635fea..75ed919b78b08977050c7bcf623b8a56b1e82424 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -22,6 +22,9 @@ struct XFont {
     XftFont* match;
 };
 
+#define PRESSED(btn) \
+    ((KeyBtnState & (1 << (btn + 7))) == (1 << (btn + 7)))
+
 /******************************************************************************/
 static void die(const char* msg);
 
@@ -153,11 +156,6 @@ void win_loop(void) {
     while (1) job_poll(Timeout);
 }
 
-bool win_btnpressed(int btn) {
-    int btnmask = (1 << (btn + 7));
-    return ((KeyBtnState & btnmask) == btnmask);
-}
-
 WinRegion win_getregion(void) {
     return Focused;
 }
@@ -473,7 +471,7 @@ static void xbtnmotion(XEvent* e) {
     KeyBtnState = e->xbutton.state;
     int x = e->xbutton.x, y = e->xbutton.y;
     get_position(Focused, x, y, &row, &col);
-    if (win_btnpressed(MouseLeft))
+    if (PRESSED(MouseLeft))
         view_setcursor(win_view(Focused), row, col, true);
 }
 
@@ -607,9 +605,9 @@ static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) {
     if (!pressed) return;
     count = ((X.now - before) <= (uint64_t)ClickTime ? count+1 : 1);
     before = X.now;
-    if (win_btnpressed(MouseRight)) {
+    if (PRESSED(MouseRight)) {
         puts("fetch tag");
-    }  else if (win_btnpressed(MouseMiddle)) {
+    }  else if (PRESSED(MouseMiddle)) {
         puts("exec with arg");
     } else {
         if (count == 1)
@@ -623,7 +621,7 @@ static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) {
 
 static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) {
     if (pressed) return;
-    if (win_btnpressed(MouseLeft)) {
+    if (PRESSED(MouseLeft)) {
         cut(NULL);
     } else {
         char* str = view_fetch(win_view(id), row, col, riscmd);
@@ -634,7 +632,7 @@ static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) {
 
 static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) {
     if (pressed) return;
-    if (win_btnpressed(MouseLeft)) {
+    if (PRESSED(MouseLeft)) {
         paste(NULL);
     } else {
         SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);