If you visit Openbox's wiki page on the subject, they eventually send you to this forum post. While the technique does work, it does not feel nearly as smooth as the Windows 7 version does. So, I decided to think about what was I actually trying to accomplish and found a different way to get the snap feature to work and it feels a lot smoother to me.
Open up ~/.config/openbox/rc.xml in your favorite editor.
Add this keybinding to the keybind section:
<!-- Window Tiling: Emulates Windows 7 Snap feature -->
<keybind key="W-Left">
<action name="UnmaximizeFull"/>
<action name="MaximizeVert"/>
<action name="MoveResizeTo">
<width>50%</width>
</action>
<action name="MoveToEdgeWest"/>
</keybind>
<keybind key="W-Right">
<action name="UnmaximizeFull"/>
<action name="MaximizeVert"/>
<action name="MoveResizeTo">
<width>50%</width>
</action>
<action name="MoveToEdgeEast"/>
</keybind>
Save the file and reload Openbox.
Now, this will allow windows to be thrown to the left and the right using Window Key + Left/Right, respectively, and will maximize them and then resize them to 50% of your screen width. In addition, if you have multiple monitors, this will allow you to cross boundaries to the next monitor. There are, however, two, minor flaws with this approach. Here are the flaws and their fixes. (Please make sure you don't bind the keys twice. Keybindings should be unique.)
First, there is no way to go back to the "regular" size of the window if it undocks from the edges. In Windows 7, if you are docked to the left and hit the "Windows + Right" key, you will return to the original window size in between docking it to the left. In the case of my solution, this will never happen. However, a default setting in rc.xml should already take care of this problem. If, at any time, you hit "Windows Key + Down," your window should undock and return to it's normal window size before it was maximized and resized to the right or left. I haven't looked into whether keybindings allow for conditional statements ("if maximized, then just unmaximize"), but it doesn't bother me so I'll leave that as an exercise to you.
Note, the following XML is what you should already have in your rc.xml to configure your unmaximize a window.
<keybind key="W-Down">
<action name="Unmaximize" />
</keybind>
The second issue that you may run into is that if you have other window open in between the window that is currently being thrown to the right or the left of your screen, it will first dock itself against those other windows (meaning you have to hit right or left more times to get it to the edge of your screen). This, by default, is a feature that is turned on in Openbox which is snap-to-windows. I will admit to not having figured out a fix for this, but, in all honesty, it's never really bothered me.
That's about it. Let me know if you have any suggestions for improving upon what I've done and I will happily update this post to reflect those changes.
10 comments:
I did it another way. Maybe you like to check them out:
http://ubuntuforums.org/showthread.php?p=12184849#post12184849
Hi, you might want to check out my little project: https://github.com/lawl/opensnap
It allows you to trigger snap like features by dragging a window to the screen borders, like in W7 :)
I checked them out.
It comes quite close, but is still different:
Aero Snap: drag the window title, move them to the border --> change the window state
Opensnap: drag something on the border, drop --> change the window state
The later causes some problems:
If I drag a tab to move them, hit the left border and let lose, it changes the window state.
The same is true for highlighted text, icons, ...
Hi (and thanks for your feedback)
This is a limitation by design. The problem is, this is normally the job of the window manager and not some 3th party app. The way i wrote it, it should work with most WM's (i change them frequently).
Opensnap can't possibly know what you're dragging (only the WM knows).
Just stumbled across this post and thought I might share. Thanks for trying it out :)
I forgot to tell you in the first place:
I made some adjustments to "opensnap.c":
- I changed "%u" to "%lu"
- I changed "usleep(10000)" to "usleep(400000)"
I got minor compiler errors:
http://pastebin.com/eKkdf47y
which I fixed by changing "%u" to "%lu":
http://pastebin.com/yXrepGhA
I could run opensnap, but snapping wasn't working.
I believe my pc was to slow for "usleep(10000)".
I fixed this by using "usleep(400000)".
(Openbox default threshold is 400ms for border actions.)
Maybe you make them the default.
I like to suggest a few other things:
- short and long parameter (-h|--help, -d|--daemon, ...)
- a parameter "--version"
I created a debian package for it:
http://media.cdn.ubuntu-de.org/forum/attachments/43/36/4769962-opensnap_0.8-1_i386.deb
Maybe you check them out.
these were just warnings, but thanks, i've fixed them all now, so the compiler is happy :)
regarding the usleep issue, that's strange, because 10000 are 1 millisecond, which your pc should easily do. 400 ms is too slow for me, i drag faster ;-)
However I think that wasn't the issue, I fixed some really stupid bitmask comparison fail. That might have been the issue, would you mind to test again?
As for the short and long parameters. Good idea, but i'm just to lazy to implement them right now, mainly because i have no use for them. Maybe later.
Oh, und du bist ja deutscher. Super, danke fürs .deb bauen :)
Your last changes fixed it.
About the debian package, gern geschehen. :D
Do you installed it?
If so, I like you to check out:
/usr/share/doc/opensnap/README
/usr/share/applications/opensnap.desktop
/etc/opensnap/hit_*
Maybe you use some of them?
About window tracking, I found this:
http://pastebin.com/wi59Q7Re
Post a Comment