[hackers] [wmii] Float detection enhancements. Add float=always and float=never to clients. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Thu, 10 Jun 2010 23:50:17 +0000 (UTC)

changeset: 2714:c645a195334f
user: Kris Maglione <kris_AT_suckless.org>
date: Thu Jun 10 01:14:48 2010 -0400
files: alternative_wmiircs/python/pygmi/event.py alternative_wmiircs/python/pygmi/fs.py cmd/wmii/client.c cmd/wmii/column.c cmd/wmii/dat.h cmd/wmii/float.c cmd/wmii/message.c cmd/wmii/view.c man/wmii.man1
description:
Float detection enhancements. Add float=always and float=never to clients.

diff -r c45fcf0644a5 -r c645a195334f alternative_wmiircs/python/pygmi/event.py
--- a/alternative_wmiircs/python/pygmi/event.py Wed Jun 09 00:19:47 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/event.py Thu Jun 10 01:14:48 2010 -0400
@@ -40,7 +40,7 @@
             elif isinstance(a, basestring):
                 a = a.__eq__
             elif isinstance(a, (list, tuple, set)):
- a = curry(lambda ary, k: k in ary, a)
+ a = (lambda ary: (lambda k: k in ary))(a)
             elif hasattr(a, 'search'):
                 a = a.search
             else:
@@ -67,10 +67,11 @@
         (1, 'foo'), (2: 'foo'), (3: 'foo'), (4: 'bar')
     """
     for k, v in items:
- if not isinstance(k, (list, tuple)):
- k = k,
- for key in k:
- yield key, v
+ if isinstance(k, (list, tuple)):
+ for key in k:
+ yield key, v
+ else:
+ yield k, v
 
 class Events():
     """
@@ -276,12 +277,11 @@
             raise AttributeError()
         if hasattr(self, name + '_'):
             return getattr(self, name + '_')
- def action(args=''):
- cmd = pygmi.find_script(name)
- if cmd:
- call(pygmi.shell, '-c', '$* %s' % args, '--', cmd,
- background=True)
- return action
+ cmd = pygmi.find_script(name)
+ if not cmd:
+ raise AttributeError()
+ return lambda args='': call(pygmi.shell, '-c', '$* %s' % args, '--', cmd,
+ background=True)
 
     def _call(self, args):
         """
diff -r c45fcf0644a5 -r c645a195334f alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Wed Jun 09 00:19:47 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Thu Jun 10 01:14:48 2010 -0400
@@ -8,7 +8,7 @@
 from pygmi.util import prop
 
 __all__ = ('wmii', 'Tags', 'Tag', 'Area', 'Frame', 'Client',
- 'Button', 'Colors', 'Color', 'Toggle')
+ 'Button', 'Colors', 'Color', 'Toggle', 'Always', 'Never')
 
 spacere = re.compile(r'\s')
 
@@ -19,9 +19,13 @@
 @apply
 class Toggle(utf8):
     def __unicode__(self):
- return u'Toggle'
- def __repr__(self):
- return 'Toggle'
+ return unicode(self.__class__.__name__)
+@apply
+class Always(Toggle.__class__):
+ pass
+@apply
+class Never(Toggle.__class__):
+ pass
 
 def constrain(min, max, val):
     if val < min:
@@ -616,7 +620,8 @@
     def quotevalue(cls, val):
         if val is True: return "on"
         if val is False: return "off"
- if val is Toggle: return "toggle"
+ if val in (Toggle, Always, Never):
+ return unicode(val).lower()
         return unicode(val)
 
     def __get__(self, obj, cls):
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/client.c
--- a/cmd/wmii/client.c Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/client.c Thu Jun 10 01:14:48 2010 -0400
@@ -313,11 +313,7 @@
 
         r = client_grav(c, ZR);
 
- hide = false;
- if(!c->sel || c->sel->view != selview)
- hide = true;
-
- XGrabServer(display);
+ hide = (!c->sel || c->sel->view != selview);
 
         /* In case the client is already destroyed. */
         traperrors(true);
@@ -328,25 +324,24 @@
         else
                 reparentwindow(&c->w, &scr.root, r.min);
 
- if(starting > -1)
+ if(starting >= 0)
                 XRemoveFromSaveSet(display, c->w.xid);
 
- traperrors(false);
- XUngrabServer(display);
-
         none = nil;
         client_setviews(c, &none);
- if(starting > -1)
+ if(starting >= 0)
                 client_unmap(c, WithdrawnState);
         refree(&c->tagre);
         refree(&c->tagvre);
         free(c->retags);
 
+ traperrors(false);
+
         destroywindow(c->framewin);
 
         ewmh_destroyclient(c);
         group_remove(c);
- if(starting > -1)
+ if(starting >= 0)
                 event("DestroyClient %#C\n", c);
 
         event_flush(FocusChangeMask, true);
@@ -427,6 +422,8 @@
 
 bool
 client_floats_p(Client *c) {
+ if(c->floating == Never)
+ return false;
         return c->trans
             || c->floating
             || c->fixedsize
@@ -533,8 +530,7 @@
 
         Dprint(DFocus, "client_focus([%#C]%C)\n", c, c);
         Dprint(DFocus, "\t[%#C]%C\n\t=> [%#C]%C\n",
- disp.focus, disp.focus,
- c, c);
+ disp.focus, disp.focus, c, c);
 
         if(disp.focus != c) {
                 if(c && !c->sel->collapsed) {
@@ -748,7 +744,6 @@
         char *str;
 
         c->name[0] = '\0';
-
         if((str = windowname(&c->w))) {
                 utflcpy(c->name, str, sizeof c->name);
                 free(str);
@@ -1185,7 +1180,7 @@
 
                 cur = nil;
                 if(!strcmp(buf+n, "~"))
- c->floating = add;
+ c->floating = add ? On : Never;
                 else
                 if(!strcmp(buf+n, "!") || !strcmp(buf+n, "sel"))
                         cur = selview->name;
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/column.c
--- a/cmd/wmii/column.c Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/column.c Thu Jun 10 01:14:48 2010 -0400
@@ -105,7 +105,8 @@
 column_insert(Area *a, Frame *f, Frame *pos) {
 
         f->area = a;
- f->client->floating = false;
+ if(f->client->floating == On)
+ f->client->floating = Off;
         f->screen = a->screen;
         f->column = area_idx(a);
         frame_insert(f, pos);
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/dat.h Thu Jun 10 01:14:48 2010 -0400
@@ -23,6 +23,9 @@
 #define FOCUSCOLORS "#000000 #81654f #000000"
 #define NORMCOLORS "#000000 #c1c48b #81654f"
 
+/* From CGO */
+#define assert_equal(x, y) typedef char _##x##_does_not_equal_##y[((x)-(y))*((x)-(y))*-2+1]
+
 enum {
         PingTime = 10000,
         PingPeriod = 4000,
@@ -72,11 +75,16 @@
          (x) == Off ? "off" : \
          (x) == Toggle ? "toggle" : "<toggle>")
 enum {
+ Never = -1,
         Off,
         On,
+ /* Xlib defines this. :( */
+ // Always,
         Toggle,
 };
 
+assert_equal(Always, 2);
+
 enum Barpos {
         BBottom,
         BTop,
@@ -173,7 +181,7 @@
         int pid;
         int dead;
         int fullscreen;
- bool floating;
+ int floating;
         bool fixedsize;
         bool urgent;
         bool borderless;
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/float.c
--- a/cmd/wmii/float.c Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/float.c Thu Jun 10 01:14:48 2010 -0400
@@ -10,7 +10,8 @@
 void
 float_attach(Area *a, Frame *f) {
 
- f->client->floating = true;
+ if(f->client->floating == Off)
+ f->client->floating = On;
 
         f->r = f->floatr;
         float_placeframe(f);
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/message.c
--- a/cmd/wmii/message.c Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/message.c Thu Jun 10 01:14:48 2010 -0400
@@ -119,13 +119,12 @@
         "show",
         "squeeze",
 };
-#ifdef notdef
+static char* floatingtab[] = {
+ "never", "off", "on", "always"
+};
 static char* toggletab[] = {
- "off",
- "on",
- "toggle",
+ "off", "on", "toggle",
 };
-#endif
 
 /* Edit ,y/^[a-zA-Z].*\n.* {\n/d
  * Edit s/^([a-zA-Z].*)\n(.*) {\n/\1 \2;\n/
@@ -170,6 +169,18 @@
 }
 
 static int
+_lsearch(char *from, char **tab, int ntab) {
+ int i;
+
+ if(from != nil)
+ for(i=0; i < ntab; i++)
+ if(!strcmp(from, tab[i]))
+ return i;
+ error(Ebadvalue);
+ return 0;
+}
+
+static int
 getsym(char *s) {
         return _bsearch(s, symtab, nelem(symtab));
 }
@@ -186,13 +197,7 @@
 
 static int
 gettoggle(char *s) {
- switch(getsym(s)) {
- case LON: return On;
- case LOFF: return Off;
- case LTOGGLE: return Toggle;
- default: error(Ebadusage);
- }
- return -1;
+ return _lsearch(s, toggletab, nelem(toggletab));
 }
 
 static int
@@ -384,7 +389,7 @@
 readctl_client(Client *c) {
         bufclear();
         bufprint("%#C\n", c);
- bufprint("floating %s\n", TOGGLE(c->floating));
+ bufprint("floating %s\n", floatingtab[c->floating + 1]);
         if(c->fullscreen >= 0)
                 bufprint("fullscreen %d\n", c->fullscreen);
         else
@@ -419,7 +424,7 @@
 
         switch(getsym(s)) {
         case LFLOATING:
- toggle(c->floating, gettoggle(m->pos));
+ c->floating = -1 + _lsearch(msg_getword(m), floatingtab, nelem(floatingtab));
                 break;
         case LFULLSCREEN:
                 s = msg_getword(m);
diff -r c45fcf0644a5 -r c645a195334f cmd/wmii/view.c
--- a/cmd/wmii/view.c Wed Jun 09 00:19:47 2010 -0400
+++ b/cmd/wmii/view.c Thu Jun 10 01:14:48 2010 -0400
@@ -364,13 +364,18 @@
 
         oldsel = v->oldsel;
         a = v->sel;
- if(client_floats_p(c)) {
+ if(c->floating == Never)
+ a = view_findarea(v, v->selscreen, v->selcol, false);
+ else if(client_floats_p(c)) {
                 if(v->sel != v->floating && c->fullscreen < 0)
                         oldsel = v->sel;
                 a = v->floating;
         }
- else if((ff = client_groupframe(c, v)))
+ else if((ff = client_groupframe(c, v))) {
                 a = ff->area;
+ if(v->oldsel && ff->client == view_selclient(v))
+ a = v->oldsel;
+ }
         else if(v->sel->floating) {
                 if(v->oldsel)
                         a = v->oldsel;
@@ -382,7 +387,7 @@
                      || c->sel && c->sel->area && !c->sel->area->floating)
                         a = v->firstarea;
         }
- if(!a->floating && view_fullscreen_p(v, a->screen))
+ if(!a->floating && c->floating != Never && view_fullscreen_p(v, a->screen))
                 a = v->floating;
 
         area_attach(a, f);
diff -r c45fcf0644a5 -r c645a195334f man/wmii.man1
--- a/man/wmii.man1 Wed Jun 09 00:19:47 2010 -0400
+++ b/man/wmii.man1 Thu Jun 10 01:14:48 2010 -0400
@@ -332,9 +332,13 @@
         of the client. The following commands may be written to
         it:
>>
- : floating <on | off | toggle>
+ : floating <on | off | always | never>
                 Defines whether this client is likely to float when
- attached to a new view.
+ attached to a new view. Ordinarilly, the value
+ changes automatically whenever the window is
+ moved between the floating and managed layers.
+ However, setting a value of _always_ or _never_
+ overrides this behavior.
         : fullscreen <on | off | toggle>
                 Sets the client's fullscreen state.
         : group <group id>
Received on Thu Jun 10 2010 - 23:50:17 UTC

This archive was generated by hypermail 2.2.0 : Fri Jun 11 2010 - 00:00:14 UTC