JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix selection clearing
[st.git] / st.c
diff --git a/st.c b/st.c
index 8475878..96111a0 100644 (file)
--- a/st.c
+++ b/st.c
@@ -19,6 +19,7 @@
 #include <sys/wait.h>
 #include <time.h>
 #include <unistd.h>
+#include <libgen.h>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -108,7 +109,6 @@ enum term_mode {
        MODE_CRLF        = 16,
        MODE_MOUSEBTN    = 32,
        MODE_MOUSEMOTION = 64,
-       MODE_MOUSE       = 32|64,
        MODE_REVERSE     = 128,
        MODE_KBDLOCK     = 256,
        MODE_HIDE        = 512,
@@ -118,6 +118,11 @@ enum term_mode {
        MODE_8BIT        = 8192,
        MODE_BLINK       = 16384,
        MODE_FBLINK      = 32768,
+       MODE_FOCUS       = 65536,
+       MODE_MOUSEX10    = 131072,
+       MODE_MOUSEMANY   = 262144,
+       MODE_MOUSE       = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
+                          |MODE_MOUSEMANY,
 };
 
 enum escape_state {
@@ -218,6 +223,7 @@ typedef struct {
        XIC xic;
        Draw draw;
        Visual *vis;
+       XSetWindowAttributes attrs;
        int scr;
        bool isfixed; /* is fixed geometry? */
        int fx, fy, fw, fh; /* fixed geometry */
@@ -244,16 +250,21 @@ typedef struct {
        signed char crlf;               /* crlf mode          */
 } Key;
 
-/* TODO: use better name for vars... */
 typedef struct {
        int mode;
        int type;
        int snap;
-       int bx, by;
-       int ex, ey;
+       /*
+        * Selection variables:
+        * nb – normalized coordinates of the beginning of the selection
+        * ne – normalized coordinates of the end of the selection
+        * ob – original coordinates of the beginning of the selection
+        * oe – original coordinates of the end of the selection
+        */
        struct {
                int x, y;
-       } b, e;
+       } nb, ne, ob, oe;
+
        char *clip;
        Atom xtarget;
        bool alt;
@@ -366,6 +377,7 @@ static void xloadfonts(char *, int);
 static int xloadfontset(Font *);
 static void xsettitle(char *);
 static void xresettitle(void);
+static void xsetpointermotion(int);
 static void xseturgency(int);
 static void xsetsel(char*);
 static void xtermclear(int, int, int, int);
@@ -390,6 +402,7 @@ static void selclear(XEvent *);
 static void selrequest(XEvent *);
 
 static void selinit(void);
+static void selsort(void);
 static inline bool selected(int, int);
 static void selcopy(void);
 static void selscroll(int, int);
@@ -438,6 +451,7 @@ static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
 static char *opt_font = NULL;
+static int oldbutton = 3; /* button event on startup: 3 = release */
 
 static char *usedfont = NULL;
 static int usedfontsize = 0;
@@ -630,12 +644,12 @@ utf8size(char *s) {
        }
 }
 
-void
+static void
 selinit(void) {
        memset(&sel.tclick1, 0, sizeof(sel.tclick1));
        memset(&sel.tclick2, 0, sizeof(sel.tclick2));
        sel.mode = 0;
-       sel.bx = -1;
+       sel.ob.x = -1;
        sel.clip = NULL;
        sel.xtarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
        if(sel.xtarget == None)
@@ -658,25 +672,33 @@ y2row(int y) {
        return LIMIT(y, 0, term.row-1);
 }
 
+static void
+selsort(void) {
+       if(sel.ob.y == sel.oe.y) {
+               sel.nb.x = MIN(sel.ob.x, sel.oe.x);
+               sel.ne.x = MAX(sel.ob.x, sel.oe.x);
+       } else {
+               sel.nb.x = sel.ob.y < sel.oe.y ? sel.ob.x : sel.oe.x;
+               sel.ne.x = sel.ob.y < sel.oe.y ? sel.oe.x : sel.ob.x;
+       }
+       sel.nb.y = MIN(sel.ob.y, sel.oe.y);
+       sel.ne.y = MAX(sel.ob.y, sel.oe.y);
+}
+
 static inline bool
 selected(int x, int y) {
-       int bx, ex;
-
-       if(sel.ey == y && sel.by == y) {
-               bx = MIN(sel.bx, sel.ex);
-               ex = MAX(sel.bx, sel.ex);
-
-               return BETWEEN(x, bx, ex);
-       }
+       if(sel.ne.y == y && sel.nb.y == y)
+               return BETWEEN(x, sel.nb.x, sel.ne.x);
 
        if(sel.type == SEL_RECTANGULAR) {
-               return ((sel.b.y <= y && y <= sel.e.y)
-                       && (sel.b.x <= x && x <= sel.e.x));
+               return ((sel.nb.y <= y && y <= sel.ne.y)
+                       && (sel.nb.x <= x && x <= sel.ne.x));
        }
-       return ((sel.b.y < y && y < sel.e.y)
-               || (y == sel.e.y && x <= sel.e.x))
-               || (y == sel.b.y && x >= sel.b.x
-                       && (x <= sel.e.x || sel.b.y != sel.e.y));
+
+       return ((sel.nb.y < y && y < sel.ne.y)
+               || (y == sel.ne.y && x <= sel.ne.x))
+               || (y == sel.nb.y && x >= sel.nb.x
+                       && (x <= sel.ne.x || sel.nb.y != sel.ne.y));
 }
 
 void
@@ -762,22 +784,18 @@ getbuttoninfo(XEvent *e) {
 
        sel.alt = IS_SET(MODE_ALTSCREEN);
 
-       sel.ex = x2col(e->xbutton.x);
-       sel.ey = y2row(e->xbutton.y);
+       sel.oe.x = x2col(e->xbutton.x);
+       sel.oe.y = y2row(e->xbutton.y);
 
-       if (sel.by < sel.ey
-                       || (sel.by == sel.ey && sel.bx < sel.ex)) {
-               selsnap(sel.snap, &sel.bx, &sel.by, -1);
-               selsnap(sel.snap, &sel.ex, &sel.ey, +1);
+       if(sel.ob.y < sel.oe.y
+                       || (sel.ob.y == sel.oe.y && sel.ob.x < sel.oe.x)) {
+               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
+               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
        } else {
-               selsnap(sel.snap, &sel.ex, &sel.ey, -1);
-               selsnap(sel.snap, &sel.bx, &sel.by, +1);
+               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, -1);
+               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, +1);
        }
-
-       sel.b.x = sel.by < sel.ey ? sel.bx : sel.ex;
-       sel.b.y = MIN(sel.by, sel.ey);
-       sel.e.x = sel.by < sel.ey ? sel.ex : sel.bx;
-       sel.e.y = MAX(sel.by, sel.ey);
+       selsort();
 
        sel.type = SEL_REGULAR;
        for(type = 1; type < LEN(selmasks); ++type) {
@@ -794,14 +812,21 @@ mousereport(XEvent *e) {
            button = e->xbutton.button, state = e->xbutton.state,
            len;
        char buf[40];
-       static int ob, ox, oy;
+       static int ox, oy;
 
        /* from urxvt */
        if(e->xbutton.type == MotionNotify) {
-               if(!IS_SET(MODE_MOUSEMOTION) || (x == ox && y == oy))
+               if(x == ox && y == oy)
+                       return;
+               if(!IS_SET(MODE_MOUSEMOTION) && !IS_SET(MODE_MOUSEMANY))
+                       return;
+               /* MOUSE_MOTION: no reporting if no button is pressed */
+               if(IS_SET(MODE_MOUSEMOTION) && oldbutton == 3)
                        return;
-               button = ob + 32;
-               ox = x, oy = y;
+
+               button = oldbutton + 32;
+               ox = x;
+               oy = y;
        } else if(!IS_SET(MODE_MOUSESGR)
                        && (e->xbutton.type == ButtonRelease
                                || button == AnyButton)) {
@@ -811,14 +836,17 @@ mousereport(XEvent *e) {
                if(button >= 3)
                        button += 64 - 3;
                if(e->xbutton.type == ButtonPress) {
-                       ob = button;
-                       ox = x, oy = y;
+                       oldbutton = button;
+                       ox = x;
+                       oy = y;
                }
        }
 
-       button += (state & ShiftMask   ? 4  : 0)
-               + (state & Mod4Mask    ? 8  : 0)
-               + (state & ControlMask ? 16 : 0);
+       if(!IS_SET(MODE_MOUSEX10)) {
+               button += (state & ShiftMask   ? 4  : 0)
+                       + (state & Mod4Mask    ? 8  : 0)
+                       + (state & ControlMask ? 16 : 0);
+       }
 
        len = 0;
        if(IS_SET(MODE_MOUSESGR)) {
@@ -827,7 +855,8 @@ mousereport(XEvent *e) {
                                e->xbutton.type == ButtonRelease ? 'm' : 'M');
        } else if(x < 223 && y < 223) {
                len = snprintf(buf, sizeof(buf), "\033[M%c%c%c",
-                               32+button, 32+x+1, 32+y+1);
+                               IS_SET(MODE_MOUSEX10)? button-1 : 32+button,
+                               32+x+1, 32+y+1);
        } else {
                return;
        }
@@ -859,15 +888,11 @@ bpress(XEvent *e) {
                gettimeofday(&now, NULL);
 
                /* Clear previous selection, logically and visually. */
-               if(sel.bx != -1) {
-                       sel.bx = -1;
-                       tsetdirt(sel.b.y, sel.e.y);
-                       draw();
-               }
+               selclear(NULL);
                sel.mode = 1;
                sel.type = SEL_REGULAR;
-               sel.ex = sel.bx = x2col(e->xbutton.x);
-               sel.ey = sel.by = y2row(e->xbutton.y);
+               sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
+               sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
 
                /*
                 * If the user clicks below predefined timeouts specific
@@ -880,12 +905,9 @@ bpress(XEvent *e) {
                } else {
                        sel.snap = 0;
                }
-               selsnap(sel.snap, &sel.bx, &sel.by, -1);
-               selsnap(sel.snap, &sel.ex, &sel.ey, +1);
-               sel.b.x = sel.bx;
-               sel.b.y = sel.by;
-               sel.e.x = sel.ex;
-               sel.e.y = sel.ey;
+               selsnap(sel.snap, &sel.ob.x, &sel.ob.y, -1);
+               selsnap(sel.snap, &sel.oe.x, &sel.oe.y, +1);
+               selsort();
 
                /*
                 * Draw selection, unless it's regular and we don't want to
@@ -893,7 +915,7 @@ bpress(XEvent *e) {
                 */
                if(sel.snap != 0) {
                        sel.mode++;
-                       tsetdirt(sel.b.y, sel.e.y);
+                       tsetdirt(sel.nb.y, sel.ne.y);
                        draw();
                }
                sel.tclick2 = sel.tclick1;
@@ -907,14 +929,14 @@ selcopy(void) {
        int x, y, bufsize, size, i, ex;
        Glyph *gp, *last;
 
-       if(sel.bx == -1) {
+       if(sel.ob.x == -1) {
                str = NULL;
        } else {
-               bufsize = (term.col+1) * (sel.e.y-sel.b.y+1) * UTF_SIZ;
+               bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ;
                ptr = str = xmalloc(bufsize);
 
                /* append every set & selected glyph to the selection */
-               for(y = sel.b.y; y < sel.e.y + 1; y++) {
+               for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
                        gp = &term.line[y][0];
                        last = gp + term.col;
 
@@ -940,20 +962,20 @@ selcopy(void) {
                         * st.
                         * FIXME: Fix the computer world.
                         */
-                       if(y < sel.e.y && !((gp-1)->mode & ATTR_WRAP))
+                       if(y < sel.ne.y && !((gp-1)->mode & ATTR_WRAP))
                                *ptr++ = '\n';
 
                        /*
                         * If the last selected line expands in the selection
                         * after the visible text '\n' is appended.
                         */
-                       if(y == sel.e.y) {
+                       if(y == sel.ne.y) {
                                i = term.col;
                                while(--i > 0 && term.line[y][i].c[0] == ' ')
                                        /* nothing */;
-                               ex = sel.e.x;
-                               if(sel.b.y == sel.e.y && sel.e.x < sel.b.x)
-                                       ex = sel.b.x;
+                               ex = sel.ne.x;
+                               if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
+                                       ex = sel.nb.x;
                                if(i < ex)
                                        *ptr++ = '\n';
                        }
@@ -1016,10 +1038,10 @@ clippaste(const Arg *dummy) {
 
 void
 selclear(XEvent *e) {
-       if(sel.bx == -1)
+       if(sel.ob.x == -1)
                return;
-       sel.bx = -1;
-       tsetdirt(sel.b.y, sel.e.y);
+       sel.ob.x = -1;
+       tsetdirt(sel.nb.y, sel.ne.y);
 }
 
 void
@@ -1082,13 +1104,13 @@ brelease(XEvent *e) {
                selpaste(NULL);
        } else if(e->xbutton.button == Button1) {
                if(sel.mode < 2) {
-                       sel.bx = -1;
+                       selclear(NULL);
                } else {
                        getbuttoninfo(e);
                        selcopy();
                }
                sel.mode = 0;
-               term.dirty[sel.ey] = 1;
+               tsetdirt(sel.nb.y, sel.ne.y);
        }
 }
 
@@ -1105,15 +1127,14 @@ bmotion(XEvent *e) {
                return;
 
        sel.mode++;
-       oldey = sel.ey;
-       oldex = sel.ex;
-       oldsby = sel.b.y;
-       oldsey = sel.e.y;
+       oldey = sel.oe.y;
+       oldex = sel.oe.x;
+       oldsby = sel.nb.y;
+       oldsey = sel.ne.y;
        getbuttoninfo(e);
 
-       if(oldey != sel.ey || oldex != sel.ex) {
-               tsetdirt(MIN(sel.b.y, oldsby), MAX(sel.e.y, oldsey));
-       }
+       if(oldey != sel.oe.y || oldex != sel.oe.x)
+               tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
 }
 
 void
@@ -1411,31 +1432,30 @@ tscrollup(int orig, int n) {
 
 void
 selscroll(int orig, int n) {
-       if(sel.bx == -1)
+       if(sel.ob.x == -1)
                return;
 
-       if(BETWEEN(sel.by, orig, term.bot) || BETWEEN(sel.ey, orig, term.bot)) {
-               if((sel.by += n) > term.bot || (sel.ey += n) < term.top) {
-                       sel.bx = -1;
+       if(BETWEEN(sel.ob.y, orig, term.bot) || BETWEEN(sel.oe.y, orig, term.bot)) {
+               if((sel.ob.y += n) > term.bot || (sel.oe.y += n) < term.top) {
+                       selclear(NULL);
                        return;
                }
                if(sel.type == SEL_RECTANGULAR) {
-                       if(sel.by < term.top)
-                               sel.by = term.top;
-                       if(sel.ey > term.bot)
-                               sel.ey = term.bot;
+                       if(sel.ob.y < term.top)
+                               sel.ob.y = term.top;
+                       if(sel.oe.y > term.bot)
+                               sel.oe.y = term.bot;
                } else {
-                       if(sel.by < term.top) {
-                               sel.by = term.top;
-                               sel.bx = 0;
+                       if(sel.ob.y < term.top) {
+                               sel.ob.y = term.top;
+                               sel.ob.x = 0;
                        }
-                       if(sel.ey > term.bot) {
-                               sel.ey = term.bot;
-                               sel.ex = term.col;
+                       if(sel.oe.y > term.bot) {
+                               sel.oe.y = term.bot;
+                               sel.oe.x = term.col;
                        }
                }
-               sel.b.y = sel.by, sel.b.x = sel.bx;
-               sel.e.y = sel.ey, sel.e.x = sel.ex;
+               selsort();
        }
 }
 
@@ -1766,15 +1786,30 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                        case 25: /* DECTCEM -- Text Cursor Enable Mode */
                                MODBIT(term.mode, !set, MODE_HIDE);
                                break;
-                       case 1000: /* 1000,1002: enable xterm mouse report */
+                       case 9:    /* X10 mouse compatibility mode */
+                               xsetpointermotion(0);
+                               MODBIT(term.mode, 0, MODE_MOUSE);
+                               MODBIT(term.mode, set, MODE_MOUSEX10);
+                               break;
+                       case 1000: /* 1000: report button press */
+                               xsetpointermotion(0);
+                               MODBIT(term.mode, 0, MODE_MOUSE);
                                MODBIT(term.mode, set, MODE_MOUSEBTN);
-                               MODBIT(term.mode, 0, MODE_MOUSEMOTION);
                                break;
-                       case 1002:
+                       case 1002: /* 1002: report motion on button press */
+                               xsetpointermotion(0);
+                               MODBIT(term.mode, 0, MODE_MOUSE);
                                MODBIT(term.mode, set, MODE_MOUSEMOTION);
-                               MODBIT(term.mode, 0, MODE_MOUSEBTN);
                                break;
-                       case 1006:
+                       case 1003: /* 1003: enable all mouse motions */
+                               xsetpointermotion(set);
+                               MODBIT(term.mode, 0, MODE_MOUSE);
+                               MODBIT(term.mode, set, MODE_MOUSEMANY);
+                               break;
+                       case 1004: /* 1004: send focus events to tty */
+                               MODBIT(term.mode, set, MODE_FOCUS);
+                               break;
+                       case 1006: /* 1006: extended reporting mode */
                                MODBIT(term.mode, set, MODE_MOUSESGR);
                                break;
                        case 1034:
@@ -1799,6 +1834,15 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                        case 1048:
                                tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD);
                                break;
+                       /* Not implemented mouse modes. See comments there. */
+                       case 1001: /* mouse highlight mode; can hang the
+                                     terminal by design when implemented. */
+                       case 1005: /* UTF-8 mouse mode; will confuse
+                                     applications not supporting UTF-8
+                                     and luit. */
+                       case 1015: /* urxvt mangled mouse mode; incompatible
+                                     and can be mistaken for other control
+                                     codes. */
                        default:
                                fprintf(stderr,
                                        "erresc: unknown private set/reset mode %d\n",
@@ -1830,8 +1874,6 @@ tsetmode(bool priv, bool set, int *args, int narg) {
                }
        }
 }
-#undef MODBIT
-
 
 void
 csihandle(void) {
@@ -1905,7 +1947,7 @@ csihandle(void) {
                        tputtab(1);
                break;
        case 'J': /* ED -- Clear screen */
-               sel.bx = -1;
+               selclear(NULL);
                switch(csiescseq.arg[0]) {
                case 0: /* below */
                        tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
@@ -2401,8 +2443,8 @@ tputc(char *c, int len) {
         */
        if(control && !(term.c.attr.mode & ATTR_GFX))
                return;
-       if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey))
-               sel.bx = -1;
+       if(sel.ob.x != -1 && BETWEEN(term.c.y, sel.ob.y, sel.oe.y))
+               selclear(NULL);
        if(IS_SET(MODE_WRAP) && (term.c.state & CURSOR_WRAPNEXT)) {
                term.line[term.c.y][term.c.x].mode |= ATTR_WRAP;
                tnewline(1);
@@ -2774,7 +2816,6 @@ xzoom(const Arg *arg) {
 
 void
 xinit(void) {
-       XSetWindowAttributes attrs;
        XGCValues gcvalues;
        Cursor cursor;
        Window parent;
@@ -2816,22 +2857,20 @@ xinit(void) {
        }
 
        /* Events */
-       attrs.background_pixel = dc.col[defaultbg].pixel;
-       attrs.border_pixel = dc.col[defaultbg].pixel;
-       attrs.bit_gravity = NorthWestGravity;
-       attrs.event_mask = FocusChangeMask | KeyPressMask
+       xw.attrs.background_pixel = dc.col[defaultbg].pixel;
+       xw.attrs.border_pixel = dc.col[defaultbg].pixel;
+       xw.attrs.bit_gravity = NorthWestGravity;
+       xw.attrs.event_mask = FocusChangeMask | KeyPressMask
                | ExposureMask | VisibilityChangeMask | StructureNotifyMask
                | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
-       attrs.colormap = xw.cmap;
+       xw.attrs.colormap = xw.cmap;
 
        parent = opt_embed ? strtol(opt_embed, NULL, 0) : \
                        XRootWindow(xw.dpy, xw.scr);
        xw.win = XCreateWindow(xw.dpy, parent, xw.fx, xw.fy,
                        xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
-                       xw.vis,
-                       CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
-                       | CWColormap,
-                       &attrs);
+                       xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
+                       | CWEventMask | CWColormap, &xw.attrs);
 
        memset(&gcvalues, 0, sizeof(gcvalues));
        gcvalues.graphics_exposures = False;
@@ -2846,7 +2885,7 @@ xinit(void) {
        xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
 
        /* input methods */
-       if((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
+       if((xw.xim = XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
                XSetLocaleModifiers("@im=local");
                if((xw.xim =  XOpenIM(xw.dpy, NULL, NULL, NULL)) == NULL) {
                        XSetLocaleModifiers("@im=");
@@ -3212,7 +3251,7 @@ drawregion(int x1, int y1, int x2, int y2) {
        int ic, ib, x, y, ox, sl;
        Glyph base, new;
        char buf[DRAW_BUF_SIZ];
-       bool ena_sel = sel.bx != -1;
+       bool ena_sel = sel.ob.x != -1;
 
        if(sel.alt ^ IS_SET(MODE_ALTSCREEN))
                ena_sel = 0;
@@ -3282,6 +3321,12 @@ unmap(XEvent *ev) {
 }
 
 void
+xsetpointermotion(int set) {
+       MODBIT(xw.attrs.event_mask, set, PointerMotionMask);
+       XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask, &xw.attrs);
+}
+
+void
 xseturgency(int add) {
        XWMHints *h = XGetWMHints(xw.dpy, xw.win);
 
@@ -3301,9 +3346,13 @@ focus(XEvent *ev) {
                XSetICFocus(xw.xic);
                xw.state |= WIN_FOCUSED;
                xseturgency(0);
+               if(IS_SET(MODE_FOCUS))
+                       ttywrite("\033[I", 3);
        } else {
                XUnsetICFocus(xw.xic);
                xw.state &= ~WIN_FOCUSED;
+               if(IS_SET(MODE_FOCUS))
+                       ttywrite("\033[O", 3);
        }
 }
 
@@ -3570,6 +3619,7 @@ int
 main(int argc, char *argv[]) {
        int bitm, xr, yr;
        uint wr, hr;
+       char *titles;
 
        xw.fw = xw.fh = xw.fx = xw.fy = 0;
        xw.isfixed = False;
@@ -3583,8 +3633,13 @@ main(int argc, char *argv[]) {
                break;
        case 'e':
                /* eat all remaining arguments */
-               if(argc > 1)
+               if(argc > 1) {
                        opt_cmd = &argv[1];
+                       if(argv[1] != NULL && opt_title == NULL) {
+                               titles = strdup(argv[1]);
+                               opt_title = basename(titles);
+                       }
+               }
                goto run;
        case 'f':
                opt_font = EARGF(usage());