You are not logged in.

#1 2010-08-24 20:27:49

serprex
Member
Registered: 2010-08-04
Posts: 10
Website

nobox - minimalist window managers don't have to be tiled

I originally posted to the dwm thread, since this was dwm at a time. But it seems Arch users seem to enjoyment suckless style apps, which I noticed while looking for documentation of zathura. nobox was created after I started using <decor>no</decor> with openbox

Like dwm, it seems a bit off to make a binary for nobox; there's no configuration file, just a mess of spaghetti code I made while envisioning nobox's flow control to be more of a funnel than a stack, and thus unsuitable for function oriented programming. The dependencies end with xcb, so there isn't much dependency hell to sort out anyways. Which only leaves updates a thing to profit with such, but updates are rather icky when a program invites the user to modify

Features/Functionality: AltTab (Improvements to this welcome, in particular with programs like GIMP). A memory footprint that rivals with getty. Respects WM_DELETE_WINDOW, so Firefox won't crash whenever you close a window

git repo

Current key configuration: nobox grabs all LAlt and Win key combinations. Programs like Finch will thus not work (While most games grab the keys, which will override nobox). I haven't configured Alt/Win checking in any of my shortcuts, only mouse
A+Left will move a window, A+Right resizes. W+Left maximizes, W+Right closes
Q urxvt W centerim A firefox S scite C time J maximize L close I xset dpms off P shutdown
A+Tab's inverse is A+Tilde
It's rather easy to setup keyboard shortcuts. xev is quite nice for finding keycodes. Personally, I've wonder if keycodes are more than laziness when my choice of keys is based on physical key location, and not the letter itself

Last edited by serprex (2010-08-25 15:04:38)

Offline

#2 2010-08-24 20:48:59

gtklocker
Member
Registered: 2009-09-01
Posts: 462

Re: nobox - minimalist window managers don't have to be tiled

Could you provide more details? What kind of program is this? A WM?

Offline

#3 2010-08-24 20:52:06

serprex
Member
Registered: 2010-08-04
Posts: 10
Website

Re: nobox - minimalist window managers don't have to be tiled

It's a stacking wm. I'm not really sure what details there are to provide, as it's quite simply a window manager that tries to do as little as possible without making it obvious how little it does

Offline

#4 2010-08-25 08:26:44

yasen
Member
From: Bulgaria
Registered: 2009-03-05
Posts: 39

Re: nobox - minimalist window managers don't have to be tiled

Wow, what a mess your code is! ( or more appropriately - I perceive your code as a mess )
Can you even go back to hack on that thing if you want to change something?
I'm interested to know the motivations behind your chosen coding style. That should be an interesting read if you're willing to write it. smile

Offline

#5 2010-08-25 10:28:31

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: nobox - minimalist window managers don't have to be tiled

yasen wrote:

Wow, what a mess your code is! ( or more appropriately - I perceive your code as a mess )
Can you even go back to hack on that thing if you want to change something?
I'm interested to know the motivations behind your chosen coding style. That should be an interesting read if you're willing to write it. smile

I like his style.

Offline

#6 2010-08-25 12:10:45

0mark
Member
From: earth
Registered: 2010-06-09
Posts: 162
Website

Re: nobox - minimalist window managers don't have to be tiled

Me too. Goto considered usefull wink

Well, the indentation style i do not like wink


Ceterum autem censeo Systemdinem esse delendam

Offline

#7 2010-08-25 12:29:08

alexandrite
Member
Registered: 2009-03-27
Posts: 326

Re: nobox - minimalist window managers don't have to be tiled

I am reminded of: http://xkcd.com/292/

So, I am to understand that nobox is basically a stacking WM with no window decorations or window-management besides alt+tabbing?

Offline

#8 2010-08-25 12:41:57

keenerd
Package Maintainer (PM)
Registered: 2007-02-22
Posts: 647
Website

Re: nobox - minimalist window managers don't have to be tiled

No real changes, just a bunch of whitespace and braces for easier reading.

http://kmkeen.com/tmp/nobox.c

A state engine would be appropriate to use.  Also, heavy use of function pointers would be up your alley.

The "if(0)" segment is my favorite.

Edit:  I kind of like your code.  Some communities frown on "implicit gotos" such as break or continue.  But here they are explicit!

Last edited by keenerd (2010-08-25 12:56:24)

Offline

#9 2010-08-25 12:46:49

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: nobox - minimalist window managers don't have to be tiled

I've written 68000 assembly that looks cleaner than that tongue
I don't want to pick on the code or anything but...wow


neutral

Offline

#10 2010-08-25 16:28:32

serprex
Member
Registered: 2010-08-04
Posts: 10
Website

Re: nobox - minimalist window managers don't have to be tiled

@yasen
I can hack it quite easily. I don't have to search through code, only think about the state of before and what I want after. Understanding a codebase trumps style. Fewer variables means less state, and the flow control is rather blunt. I've dealt with messier code, like a game I wrote, Crumb:

from random import*
from pyglet import*
from pyglet.gl import*
s,n,o,m,g,i,i.on_draw=lambda:glClear(g(r=1,c=1,_=iter(range(16384)))or 16384),glVertex2f,glColor3f,glRecti,globals().update,window.Window(599,599),lambda:g(r=g(p=randint(99,512),e=randint(99,512)),l=[][glBegin(1):o(1-1,1,1):n(next(_)*4-6,4)][n(next(_)*4-6,4):glEnd():o(1-1,1-1,1-1)][m(r+9,c+9,r-9,c-9):m(p+9,e+9,p-9,e-9):o(1,1-1,1-1)][m(p+4,e+4,p-4,e-4):])if r else glBegin(3)or o(1,1,1)or[n(l.pop(1-1),l.pop(1-1))for a in range(len(l)-8>>1)]and n(*l[:2])or g(r=glEnd())
i.on_mouse_drag=i.on_mouse_motion=lambda a,o,gl,_=s(),b=glLineWidth(2),i=i.set_mouse_cursor(i.get_system_mouse_cursor("crosshair")),m=(1,1,6407,5126,(GLfloat*3)()):r or(l.extend((a,o))or len(l)>3and((lambda e:any(glReadPixels(*(p,(a,o)[e]+(p-l[-1-e])*(l[e-4]-l[e-2])/(l[-3-e]-l[-1-e]))[::e-1+e]+m)or m[4][0]for p in range((o,a)[e],l[-3-e],cmp(*l[-3-e::2]))))(abs(l[-4]-l[-2])>abs(l[-3]-l[-1])))and(g(r=p,c=e)or m[4][1])and s())
app.run()

Which is the extent to which this style can go awry in python, where I'm not trying to get the smallest binary, but the smallest script (The redundancy in this snippet was written to let zlib do a better job, since I pipe this through carlae))
I began programming with Game Maker5.3, where I found out it was programmed so crudely that one's code is stored in the executable, comments included. There, I learnt to write all my code on one line (GML's syntax is _very_ loose) and so I became quite proficient at paranthesis matching since the editor didn't paranthesis match (I've since lost the knack some, but it teaches that you can adapt to whatever you want to. I apply minimalism to quite a lot in my life, and it comes down to me not asking if I can go without something, but if I could learn to go without something. I think a beautiful aesthetic is one which compels us to change for it; to sacrifice ourselves in the name of it's idealism)
So I spent three years writing the sloppiest code around so that the games I made in Game Maker would be less than a megabyte when zipped (Shivers to think I thought that was small.) I also found that I prefer expressions to statements, but I don't like cutting expressions on multiple lines to follow code guidelines which cater to people coding on a 80 character wide terminal (I get 208 characters on my wide screen monitor, and I wish it were wider. This goes back to aesthetics determining what should be, which is that my code shouldn't be shorter in width, but that my monitor should be wider. It's my fault that I don't have multiple monitors to show this code in it's true glory, and the code shouldn't be penalized into a form that it isn't for my failure)
When I stopped using functions, nobox's size dropped quite. GCC is a micro optimizer, so I'm forced to show it how to restructure my program
Then I read Fountainhead, which taught me not to be embarrassed of my code (I code in this manner naturally, and when I code my own projects out of the style, it wears on my conscious. I was worried that would get in the way if I ever got a job programming, but I found myself quite easily writing to suit Python while patching it. It isn't hard to mimic a style, I just happen to have this style as my default)
Styleless. A null program has no style, and perhaps some would say my programs lack a style. In a way, I've dealt with such in other areas. Religious types thinking that my being atheist isn't that I've decided God is too complex for a beautiful universe, but that I'm an emptiness to be filled and saved. I had my apartment to myself for a month, but as soon as my room mate moved in the house picked up her style since she brought stuff like butter knives (I hate butter knives. They're useless. They excel at nothing, so that any use one finds for them can be replaced by a more focused tool. If anything, just use a steak knife. & yet everybody has them because they're part of canon plate setting)
I've probably written enough. I've never been asked to explain myself, so this is a tad too much of a stream of consciousness

@alexandrite
Windows can also be switched with the mouse by Alt+Left, which is now making me think Alt+Middle would be nice to move without bringing to front, but that'd require another variable for a feature I'd probably never use. I'll probably make Alt+Middle give keyboard focus to a window without bringing to front instead, though I'd prefer a keyboard related thing have a keyboard equivalent (I went to check and see if I was wrong, ended up opening keenerd's tidy up, but got lost in all the whitespace and had to open up mine)
Something I never got around to doing was smart window placement. I also experimented with was having a keyboard shortcut to move the windows into a grid, and then allow window switching shortcuts which assume windows are in a grid

@keenerd
I do enjoy first class functions, Haskell proved rather nice in setting up a generic fractal renderer, and the reason the void pointer is named ret is that originally it was for telling stack a return address via GCC's label values, but after merging keyboard/mouse, I realized that two code paths can be covered by a bit, for which I found mz suitable enough. My problem with functions at a low level is that they have to follow an ABI. Personally, I'd prefer if linking included an ABI field which at least informed which registers were preserved, and perhaps more like where the return value would go and where parameters go. This would be more for processors which have a low register count (eg x86)
As for a state engine, I felt that way more when I rewrote flip, a newline converter, but that was a rather simple piece of code (yasen, an example of what motivates me with respect to thinking myself right and others wrong, compare mine to his)
Rewriting code is a good way to come to understand it. Though you'd've been quite better off replacing my low hanging fruit with the ending goto main. As for bad nesting, is it syntactically or semantically? I was unsure how to go about indenting that label

@sand_man Some assembly is clean, some isn't: C is portable assembly

Last edited by serprex (2010-08-25 20:20:24)

Offline

#11 2010-08-25 18:45:23

pogeymanz
Member
Registered: 2008-03-11
Posts: 1,020

Re: nobox - minimalist window managers don't have to be tiled

sand_man wrote:

I don't want to pick on the code or anything but...wow

Actually, it seems that is exactly what you want to do...

Offline

#12 2010-08-26 03:45:51

keenerd
Package Maintainer (PM)
Registered: 2007-02-22
Posts: 647
Website

Re: nobox - minimalist window managers don't have to be tiled

The "low hanging fruit" if(0) was meant for the next person who refactored stuff.  Or it might be a bug.  I was kind of surprised you left it in, everything else considered.  Pretty blatant waste of code.  The lack of #defines is pretty shocking too.  Usually macros are the first step in such compression.

Whitespace helps readability a lot.  Does not affect binary size.  You can always strip it later, if that kind of masochism is your thing.

The "bad nesting" comment was switch/case abuse.  Generally all the case statements are on the same indentation, syntactically.

Using ret as both a temporary pointer and as a shell command is just pointless and/or dangerous.

Do consider applying some organization and structure.  You'll be able to hold even more code in your head.

Just out of curiosity, why did you put this on github?  It does not seemvery likely that folks will send in patches.  Even if I did fix something, I'd have to reobfuscate for you.

Finally, a morbid request.  You would not happen to have any written any multithreaded programs?  It would be interesting to see such a beast.

Edit:  Just a note with Pacgraph - I am in the middle of a big rewrite to make it use R trees.  Should bump it from O(n^2) to O(log n).  Hop on over to #archlinux if you want to talk code.

Edit2:  Examining http://github.com/serprex/pacgraph/comm … 85f6d93204  the entire speed gain was from your line 445, changing the sort to a max.  Looking forward to merging.

Last edited by keenerd (2010-08-26 04:07:14)

Offline

#13 2010-08-26 04:17:36

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: nobox - minimalist window managers don't have to be tiled

Damn.



This would be a good entry for IOCCC if you obfuscate it a little more. I recommend formatting it all into a tidy block shape if you do that.

Obviously, you are a Real Programmer.

Offline

#14 2010-08-26 08:30:47

0mark
Member
From: earth
Registered: 2010-06-09
Posts: 162
Website

Re: nobox - minimalist window managers don't have to be tiled

alexandrite wrote:

I am reminded of: http://xkcd.com/292/

What? He had no dino-proof fence! Was his own fault tongue


Ceterum autem censeo Systemdinem esse delendam

Offline

Board footer

Powered by FluxBB