As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label dwm. Show all posts

After I added a keybinding for Bash, I think why not make it working globally?

Here is what I just added to my DWM configuration:

diff --git a/dwm-config.h b/dwm-config.h
index 1994463..517976b 100644
--- a/dwm-config.h
+++ b/dwm-config.h
 -125,6 +125,8  static const char *monitor_expand_cmd[] = { "monitorExpand.sh", NULL };

 static const char *lock_cmd[] = { "xlock", "-mode", "blank", "-startCmd", "monitorOff.sh", "-timeout", "15", "-dpmsoff", "1", NULL };

+static const char *ts_cmd[] = SHCMD("xdotool keyup t ; xdotool type --clearmodifiers $(date --utc +%Y-%m-%dT%H:%M:%SZ)");
+
 static Key keys[] = {
   /* modifier                     key         function        argument */
   { MODKEY,                       XK_p,       spawn,          {.v = bashrun_cmd } },
 -155,6 +157,8  static Key keys[] = {
   { MODKEY,                       XK_F2,      spawn,          {.v = monitor_switch_cmd} },
   { MODKEY,                       XK_F3,      spawn,          {.v = monitor_expand_cmd} },

+  { MODKEY|ShiftMask,             XK_t,       spawn,          {.v = ts_cmd} },
+
   { MODKEY|ShiftMask,             XK_m,       toggle_ffm,     {0} },
   { MODKEY|ShiftMask,             XK_r,       toggle_rules,   {0} },

It uses xdotool to send the key events. Since I bound it to t, it is necessary to send a keyup even in prior or the timestamp string will be eaten entirely or partially, depending on when I release the key. Also, --clearmodifiers is required, or the characters in timestamp string may trigger other keybindings in DWM.

You can bind the key in your Window Manager, some may not be able to run with sh but a simple executable file, you can always create a script and put the commands in that script and make it executable.

I was trying to update the DWM and got this error message from emerge:
dwm.c: In function 'createmon':
dwm.c:654:15: error: 'nmaster' undeclared (first use in this function)
dwm.c:654:15: note: each undeclared identifier is reported only once for each function it appears in
dwm.c: At top level:
dwm.c:1030:1: warning: 'incnmaster' defined but not used
make: *** [dwm.o] Error 1
It seems that dwm 6.0 has included the code of nmaster patch, or a re-implementation. Anyhow, you need to update your config.h for nmaster variable, even you don't use nmaster.
/* layout(s) */
// snip
static const int nmaster      = 1;    /* number of clients in master area */
// snip

static Key keys[] = {
// snip
 { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
 { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
// snip
The incnmaster function is to change the amount of clients in master area. I bind them to the keys which fits into my configuration, here is the diff I updated for this upgrade.

Before 6.0, I hadn't used nmaster patch, but I did feel the need of similar feature. There were some moments, master area is, well, too big for just one client. However, I have gridmode patch, sometimes it can sort of have the layout I need.

When I was trying to play TES: Arena in fullscreen, the screen didn't go as I expected. I saw the screen resolution changed from 1680x1050 (my native screen resolution), the game screen didn't show but a portion of X window from top-left corner.

There was a thread of discussion about this, the problem didn't exist in DWM v4.3, but that was very old version of DWM. Although there seemed to have some patch, but I didn't look into it. I didn't like to patch on my own.

I was using scaler of DOSBox at the time being in windowed mode, then I noticed there was an option fullresolution under the sdl section. The workaround is actually quite simple, you set it to your native screen resolution, so the screen resolution won't be changed after switching to fullscreen mode.

Problem solved.

You should have a default configuration file under ~/.dosbox after first-run of DOSBox, you can copy and modify it and use it with current directory as dosbox.conf when you run with dosbox .. It is documented very well, or you can read about the options here.

Note that some scaler doesn't re-scale to fill up the entire screen, you will see the picture centered at center of screen and leave a huge black border. normal2x/3x, advmame3x, and some re-scale to fill up the screen.

This may actually better than real screen mode change, by keeping the same resolution, the switching is faster than real screen mode change. You won't feel a pause during the switching.

After I had fun with Fus Ro Dah, I decided to try the first game in DOSBox, here is the commands I used to run it:

unzip Arena106Setup.zip
# file Arena106.exe
# Arena106.exe: PE32 executable (GUI) Intel 80386, for MS Windows, UPX compressed, RAR self-extracting archive
unrar e Arena106.exe
dosbox ARENA.BAT

You can download the full game for free on its website.

I have adjusted the configuration file of DOSBox, so I can have fullscreen in DWM, there seems to have bug in SDL or DWM. Save it as dosbox.conf and put it with game files, you will need to adjust it for your screen setting.

Before I changed the default normal2x scaler (you can also use command scaler to change), the game picture really reminded me of the old times. I have no idea how I could have played many games in that period of time. The text was almost unreadable for me before I changed to hq3q or advmame3x. Here are some screenshot of original pictures:



(I don't look like that in that picture at all, just random test :D)

I also had to change to CPU cycle, default was 3000, which was too slow when walking in the game.

The ZIP comes with a PDF file for instruction of using DOSBox, it also contains a list of password for copy protection, there is another Passwords.txt for easy lookup.

This certainly brought me back about two decades ago. After you bought a game, you opened the plastic wrapper, then took out a thick, well-designed, well-printed manual. You would hope there is more than just one manual, some posters or something.

You flipped over the pages, then a piece of colored plastic would fall out, it could be solid color, or two colors. You would put it on certain page which the text was printed in unreadable background colors.

But when you read through the colored plastic a number or a word would show up beneath. You then input that into a popup dialog, which showed up at random or at beginning of the game.

Meh, that was the time.

I need dwm to temporarily forget the designated tags for clients. As I mentioned how I used dwms tags, when I am working on my workspace tags, sometimes I will open a new window in Firefox. According to my rules, that new window will go to tag a, I will need to switch to tag a and tag that new window. Its only a few seconds task, but I want to avoid that.

So, I added a new function toggle_rules() to my config.h. Note that you need to remove const from your rules[]. My code is to store the original tags of each rule, then override the tags with 0 or the original tags. I have to hack in this way because I can not touch applyrules(), simply because I am not patching the dwm.c.

I also want to mention about dwm 5.9, I just updated because 5.6.1 has some problem with windows position when you re-show a window and you use topbar. The y position always being added up with the height of topbar when re-shows, I didnt check the code, but its fixed after I upgraded dwm.

A surprise is that fullscreen is also fixed. Whenever a program enters fullscreen mode (including Flash), it does not have any problem. I dont need to use monocle or floating anymore.

5.6.1 is more than two years old, I should have tried it. Just too lazy to put dwm to package.keywords. ;)

dwm stands for Dynamic Window Manager, its a dynamic tiling WM. Current stable version is 5.9, but I am using version 5.6.1, a two-year-old version, because its stable version in Gentoo.

https://lh6.googleusercontent.com/-OCbHsOhPgkE/Tie93f6lXxI/AAAAAAAACzU/efe-3B8hFyQ/s800/2011-07-21--13%25253A47%25253A55.png

Current view with tag 1 and q (KeepNote tagged with) on and layout is bstack (bottom stack). That video is just an example, no one cant even do anything with that video being played. Nyan!

1   Why I switched to dwm

My previous WM is Fluxbox and its really a great WM, I had been using it for more than two years. I like it, still do, even now I has switched to dwm. But from time to time, stacking window manager just can make you take some time to move and to resize windows, only to satisfy unnecessary adjustment. Its as if you wrote one paragraph and take three times of time of writing that paragraph to change text color/style/etc. Like TeX, you are educated to focus on your content, instead. Using tiling window manager, it makes you try less to adjust window size, to align the windows, if you used to line up windows side by side. Many stacking WM supports snapping (dwm does, too), which is helpful for arranging windows, but you might not be happy with the size of the window. So, you go back to maximize all windows, then you might keep pressing Alt+Tab to bring the underneath window to top.

I need to have more than one window to be shown at the same time, tiling would help a lot. And thats the reason that I switched to dwm. However, dwm wasnt the first tiling window manager I have tried, awesome was the first. But at the time, I didnt really get the concept. When I decided to find one to try again, dwm is one of many WM needs very less dependency. No need to learn scripting language, you just use C.

When I firstly tried, I also heard of dwm, but I didnt want to compile. Now, I prefer to compile a C program instead of using Python script or so. Compiled program should have better performance than interpreted language program. dwm is little more, it doesnt use a structured configuration file. Actually, a C code is still one, its just being parsed and compiled.

Of course, it lacks of certain flexibility since recompilation is required in order to have new configuration, in fact, restart the program is also required. However, the code of dwm is only around 2,000 lines plus your configuration C code, the compilation time is extremely fast. And once you have stable configuration, you probably wouldnt make and changes for a few months.

2   Previous experience with tiling WM

I have to admit that this wasnt my first time to try a tiling WM as I mentioned above. My first experience was with awesome. If I recall correctly, its about one week before I switched back to Enlightenment E16. I couldnt get a hold of tiling WM at that moment, too many keybinds to remember. Funny thing is that I feel I now have configured more keys than I had with awesome. Maybe its just I didnt understand the concept of tiling or how to really make a use of it.

Another one is PyTyle, its used on top of non-tiling WM, an addon. Ten-minute with it, I guess.

3   How I use dwm

3.1   The terms: client, tag, layout, view, monitor

Before I am going to get into that, there are some terms have to be explained first. If you are familiar with those, then skip this subsection.

Client is a window (program), something you spawn with, say dmenu or your favorite program launcher or you keybind for a special program in dwm. It stays in its own cell in dwm. A client must be tagged with a least one tag. By default, it will be currently viewed tag.

A view can show multi-tag at the same time, and the clients tagged with those tags will be presented with selected layout. The default available layouts, in v5.6.1, are tiling, floating, and monocle. Layout is independent from view, that is changing view doesnt cause layout change, vice versa.

One monitor can only have one view, but previous view can be brought back.

3.2   So, how?

The default tag list is 1 2 3 4 5 6 7 8 9, but Ive changed it to 1 2 3 q w e a s d. Notice where they are located on keyboard? They are in 3x3 square shape, well, sort of.

The first three 1 2 3 is used as if they are workspace, I name them workspace tags. I compose, grope, or tag clients with them. When a client is tagged with them, they have already been tagged with only one of q w e a s d, which I call them client tags.

In my rules, please see my configuration, programs I used to use are tagged with client tags. Those programs will always be spawned with generally only one of client tag, but none of workspace tags. For those are not listed in rules, they are spawned with currently viewed tag, and thats reason I always make sure my currently viewed tag is one of 1 2 3. That way, I wont have unwanted program being tagged with client tags.

Once a program spawned, I can bring one of client tags to currently viewed tag by pressing ModKey+Ctrl+Tag, then tag the program I need to current workspace tag and turn off the client tag. Or I can just switch to that client tag and tag that program, then switch back.

Most of time, my tag 1 has Firefox, terminal, and video player; tag 2 has the same Firefox and KeepNote. When I need to code, I stay at tag 1; when I need to check up my notes, I switch to tag 2. If the space isnt the issue, I just bring tag 2 to current view, so I can see all programs tagged with 1 and 2.

However, I do not always stick with these workspace tags. Some of programs I use in client tag, e.g. GIMP. If needed I can temporarily bring the tag with GIMP, then turn off after I am done. Since I keep GIMP in its own client tag, I dont need to worry that I would bring other programs with it. Thats why I decide to categorize program into their own client tags.

There is plenty of ways to use dwm, it depends how you like to do, no strict rules tell how you should use tags and view. You can even have only one tag, if you really like that, then enjoy tiling.

3.3   Configuring

My Linux distro is Gentoo. For your convenience, you can enable savedconfig USE flag and you will have a default configuration file being initialized at /etc/portage/savedconfig/x11-wm/dwm-VERSION and being pulled from that path when emerge.

When use emerge to install dwm, there is a major drawback, the configuration file can only be edited by root only and installed system-wide and single-configuration. If you are a single user, that doesnt matter; if not, you will need to manually install dwm at your own home. I am just lazy, so I use emerge and dont even bother to edit keyword file so I can use latest version.

If you need to include additional code as I do in my configuration, you put the source files at same path where dwm-VERSION at and use full path to include. Be sure to check out these patches, you might find some useful, such as new layouts.

Since you need to recompile for new configuration, that means you need to re-emerge in order to recompile. So, right now I have 99 merges history for dwm package and total merge record is 4942, which means 2% is dwm.

3.4   Status text

Its a useless feature for me, because its monochrome (there is a patch to improve, I believe) and I already have a better and working dzen system monitor. I reposition dzen to cover the status text.

3.5   About full-screen

My first trouble is program with full-screen mode, e.g. MPlayer, Flash, etc. When you enable the mode, you would see a portion of that program and you are sure the program does switch to full-screen, just other program will cover the full-screend program.

The solution is simple: 1) make the program floating, then enable the mode; or 2) switch to monocle layout, then enable the mode.

The latter method has little issue, but I wouldnt call it. The dwm bar stays on top of full-screend program. I kind of like that since I can still read my dzen system monitor.

4   Conclusion

Before I felt I need to use tiling WM, I always couldnt figure out why you want to split your screen for small areas. I have a 1680x1050 screen and I still didnt want to split it. But now I feel the programs window size isnt always affecting your working performance, it would but not entirely. In fact, split might even help the performance because you can read the reference data or whatever stuff you need alongside. You dont need to press Alt+Tab< twice just to get the information you need.

But! (There is always a but.) It might also be reducing your performance, because you can have a video playing and that would distract you. Just for the record, I have put three on at once and I hardly type anything on my keyboard.