]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring of x11.c to limit public interfaces
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 12 Apr 2018 20:08:48 +0000 (16:08 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 12 Apr 2018 20:08:48 +0000 (16:08 -0400)
inc/win.h
lib/x11.c
tide.c

index bf224cdb2974fb5d3183d11e4d9519c2575f124f..43c7226131f4c373f4af39a1bebaf792ae2b621a 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -104,12 +104,6 @@ enum {
     CLIPBOARD = 1
 };
 
-void x11_init(void);
-bool x11_keymodsset(int mask);
-void x11_window(char* name);
-bool x11_sel_get(int selid, void(*cbfn)(char*));
-bool x11_sel_set(int selid, char* str);
-
 enum {
     MouseLeft    = 1,
     MouseMiddle  = 2,
@@ -136,7 +130,11 @@ typedef struct {
     int h, w;
 } drawcsr;
 
-void win_init(KeyBinding* bindings);
+bool x11_keymodsset(int mask);
+bool x11_sel_get(int selid, void(*cbfn)(char*));
+bool x11_sel_set(int selid, char* str);
+
+void win_init(char* title, KeyBinding* bindings);
 void win_save(char* path);
 void win_loop(void);
 void win_quit(void);
index 6ec2555e3c3b9327b8b199376151e9c9262dddf8..09e3e8bf2ac93b8751b9eb495d6922f2f310c1fe 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -29,6 +29,11 @@ struct XFont {
 
 static void die(const char* msg);
 
+static WinRegion getregion(size_t x, size_t y);
+static struct XSel* selfetch(Atom atom);
+static void xftcolor(XftColor* xc, int id);
+
+static void x11_window(char* name);
 static void x11_font_load(char* name);
 static size_t x11_font_height(void);
 static size_t x11_font_width(void);
@@ -80,10 +85,6 @@ static void (*EventHandlers[LASTEvent])(XEvent*) = {
 
 /******************************************************************************/
 
-static WinRegion getregion(size_t x, size_t y);
-static struct XSel* selfetch(Atom atom);
-static void xftcolor(XftColor* xc, int id);
-
 static struct {
     Time now;
     Window root;
@@ -126,13 +127,32 @@ char* SearchTerm = NULL;
 
 /******************************************************************************/
 
-void win_init(KeyBinding* bindings) {
+void win_init(char* title, KeyBinding* bindings) {
+    Keys = bindings;
     view_init(&Regions[TAGS], NULL);
     view_init(&Regions[EDIT], NULL);
-    x11_init();
-    Keys = bindings;
-    x11_font_load(FontString);
+    signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
+    setlocale(LC_CTYPE, "");
+    XSetLocaleModifiers("");
+    /* open the X display and get basic attributes */
+    if (!(X.display = XOpenDisplay(0)))
+        die("could not open display");
+    X.root = DefaultRootWindow(X.display);
+    XWindowAttributes wa;
+    XGetWindowAttributes(X.display, X.root, &wa);
+    X.visual   = wa.visual;
+    X.colormap = wa.colormap;
+    X.screen   = DefaultScreen(X.display);
+    X.depth    = DefaultDepth(X.display, X.screen);
     x11_font_load(FontString);
+    x11_window("tide");
+    /* initialize selection atoms */
+    for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++)
+        Selections[i].atom = XInternAtom(X.display, Selections[i].name, 0);
+    SelTarget = XInternAtom(X.display, "UTF8_STRING", 0);
+    if (SelTarget == None)
+        SelTarget = XInternAtom(X.display, "STRING", 0);
+    /* Populate the  tags region */
     View* view = win_view(TAGS);
     view_putstr(view, TagString);
     view_selprev(view); // clear the selection
@@ -156,14 +176,6 @@ void win_loop(void) {
     while (1) job_poll(Timeout);
 }
 
-View* win_view(WinRegion id) {
-    return &(Regions[id == FOCUSED ? Focused : id]);
-}
-
-Buf* win_buf(WinRegion id) {
-    return &(Regions[id == FOCUSED ? Focused : id].buffer);
-}
-
 void win_quit(void) {
     static uint64_t before = 0;
     if (!win_buf(EDIT)->modified || (X.now - before) <= (uint64_t)ClickTime)
@@ -171,36 +183,21 @@ void win_quit(void) {
     before = X.now;
 }
 
-/******************************************************************************/
-
-void x11_init(void) {
-    signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
-    setlocale(LC_CTYPE, "");
-    XSetLocaleModifiers("");
-    /* open the X display and get basic attributes */
-    if (!(X.display = XOpenDisplay(0)))
-        die("could not open display");
-    X.root = DefaultRootWindow(X.display);
-    XWindowAttributes wa;
-    XGetWindowAttributes(X.display, X.root, &wa);
-    X.visual   = wa.visual;
-    X.colormap = wa.colormap;
-    X.screen   = DefaultScreen(X.display);
-    X.depth    = DefaultDepth(X.display, X.screen);
+View* win_view(WinRegion id) {
+    return &(Regions[id == FOCUSED ? Focused : id]);
+}
 
-    /* initialize selection atoms */
-    for (int i = 0; i < (sizeof(Selections) / sizeof(Selections[0])); i++)
-        Selections[i].atom = XInternAtom(X.display, Selections[i].name, 0);
-    SelTarget = XInternAtom(X.display, "UTF8_STRING", 0);
-    if (SelTarget == None)
-        SelTarget = XInternAtom(X.display, "STRING", 0);
+Buf* win_buf(WinRegion id) {
+    return &(Regions[id == FOCUSED ? Focused : id].buffer);
 }
 
+/******************************************************************************/
+
 bool x11_keymodsset(int mask) {
     return ((KeyBtnState & mask) == mask);
 }
 
-void x11_window(char* name) {
+static void x11_window(char* name) {
     /* create the main window */
     X.width = WinWidth, X.height = WinHeight;
     XWindowAttributes wa;
@@ -252,7 +249,7 @@ void x11_window(char* name) {
 
 /******************************************************************************/
 
-void x11_font_load(char* name) {
+static void x11_font_load(char* name) {
     /* init the library and the base font pattern */
     if (!FcInit())
         die("Could not init fontconfig.\n");
@@ -269,26 +266,26 @@ void x11_font_load(char* name) {
     FcPatternDestroy(match);
 }
 
-size_t x11_font_height(void) {
+static size_t x11_font_height(void) {
     return CurrFont.match->height;
 }
 
-size_t x11_font_width(void) {
+static size_t x11_font_width(void) {
     XGlyphInfo extents;
     XftTextExtentsUtf8(X.display, CurrFont.match, (const FcChar8*)"0", 1, &extents);
     return extents.xOff;
 }
 
-size_t x11_font_descent(void) {
+static size_t x11_font_descent(void) {
     return CurrFont.match->descent;
 }
 
-void getglyph(XGlyphSpec* spec, uint32_t rune) {
+static void getglyph(XGlyphSpec* spec, uint32_t rune) {
     spec->glyph = XftCharIndex(X.display, CurrFont.match, rune);
     spec->font  = CurrFont.match;
 }
 
-size_t getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, int x, int y) {
+static size_t getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, int x, int y) {
     int winx = x, winy = y;
     size_t numspecs = 0;
     for (int i = 0, xp = winx, yp = winy; i < len;) {
@@ -305,7 +302,7 @@ size_t getglyphs(XGlyphSpec* specs, const XGlyph* glyphs, int len, int x, int y)
     return numspecs;
 }
 
-void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol) {
+static void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol) {
     if (!nspecs) return;
     XftFont* font = specs[0].font;
     XftColor fgc, bgc;
@@ -325,7 +322,7 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol)
     XftColorFree(X.display, X.visual, X.colormap, &fgc);
 }
 
-void x11_draw_rect(int color, int x, int y, int width, int height) {
+static void x11_draw_rect(int color, int x, int y, int width, int height) {
     XftColor clr;
     xftcolor(&clr, color);
     XftDrawRect(X.xft, &clr, x, y, width, height);
diff --git a/tide.c b/tide.c
index 88b0ed3d58e62269487b649e02363de6bbb8dae4..80a3b2cb52689d85d4fb3aaed26ff0068760746f 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -495,8 +495,7 @@ int main(int argc, char** argv) {
     if (!ShellCmd[0]) ShellCmd[0] = "/bin/sh";
 
     /* create the window */
-    win_init(Bindings);
-    x11_window("tide");
+    win_init("tide", Bindings);
 
     /* if we still have args left we're going to open it in this instance */
     if (*argv) view_init(win_view(EDIT), *argv);