You are not logged in.
This is the result of a few things I learned today with suggestions I received. Isn't so hard to read now and I lost one grep, at least.
#! /bin/sh
while true; do
eval $(awk '/^cpu /{print "previdle=" $5 "; prevtotal=" $2+$3+$4+$5 }' /proc/stat); sleep 0.4
eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat); intervaltotal=$((total-${prevtotal:-0}))
echo -n "{#cccccc}CPU:$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))%:"
echo -n "$(awk '/MHz/ {printf "%.0f", $4}' /proc/cpuinfo | cut -c 1-4)Mhz "
echo -n "RAM:$(free -m | grep -i /cache | awk '{print $3}')Mb "
echo -n "T:$(($(cat /sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp) / 1000))C "
echo -n "BAT:$(cat /sys/class/power_supply/BAT0/status | cut -c 1-5):"
echo -n "$((100*`cat /sys/class/power_supply/BAT0/charge_now` / `cat /sys/class/power_supply/BAT0/charge_full`))% "
date +%m/%d
sleep 5
done
I've learned more with my short dabbling with ttwm than I have for some time.
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
I don't believe bash is capable of the equivalent of "inlining" short one-line functions as in the example from the previous post. I suspect bash may even create subshells for each function call (it does create a new namespace). In the later case function calls for one line of code that is not reused anywhere else would be a significant resource drain on a script like this. In either case it would be some degree of drain.
I feel your philosophy when I read your code It's somtimes a bit hard to understand but it works very fast.
The Performance Penalty for the shell functions is about 50% I guess. But you will hardly notice... Is it this discussion http://c2.com/cgi/wiki?OptimizeLater?
If your function doesn't take an argument, you could use
shopt -s expand_aliases
and aliases to simulate "inlining" of functions.
I have the feeling that it sounds very impolite when I write in english.
Offline
I have the feeling that it sounds very impolite when I write in english.
Not at all, I appreciate your points. I do like that page you linked, but I also like to disagree with it
There is a good element of personal taste in such issues though - I do find the "optimized" code easier to read myself. DWM is broken into many functions and I find that harder to read as to follow program logic I have to jump around between several different parts of the code. I (personally) prefer code that is as 'linear' as practical, because we read and understand it in a linear way.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Hi Trilby
Now this is a style question. And it's funny, I tried to implement the data structures we talked about earlyer. Of corse I made countless tiny little functions
I could not yet try it because I'm stuck in the main loop and the status function. (too few functions ) But I have tested the data structures and the functions with something like unit tests.
What do you think about unit tests and decoupling? I realized a long time ago that I am not able to read a program linear. It's just too much. But decoupling helps. You can understand one aspect of the code and change it without understanding the rest.
With this trick I can scope with many functions. You probably know this.
http://stackoverflow.com/questions/5636 … and-tricks
Hey I dont't want to change you but this decoupling, code to understand/test, Martin Fowler thing was one of the very few moments at school when I thought this is not such a bad Idea.
Last edited by wirr (2012-11-23 14:57:33)
Offline
I think you give me too much credit; I have no formal education in computer science. I'm like the drunk blues guitarist on the street corner next to the symphony hall: when some of those fancy dressed "professionals" come out talking about some esoteric aspect of music theory, I just play louder.
That said I always like learning more. From what I gather about unit testing, I believe I do a bit of that, just in a much less formal way. I often break my code up into testable units. Sometimes this is within the same program, sometimes it is with verbose printf commands that allow me to see what is happening at run time, and sometimes I copy blocks of code to another program all together just to test and/or optimize.
But after testing is over, I remove all these superfluous bits of code. While it may or may not be a popular view, I firmly believe every data structure and every code instruction (i.e. the assembly or machine code instructions the C will compile into) should carry its weight. Any data element or instruction that is not doing something vital to the program's intended function should be removed.
----
I had to look up "decoupling" in this context. The idea sounds great, but the question is what is considered a unit or building block. I can split apart a window manager into many building blocks that can be tested independently, streamlined, and polished. But in the end, the desired functional unit is the whole window manager. I feel my job would not be complete if I just made many subunits that each worked wonderfully in isolation - Once they are put back together there is another round of polishing and streamlining that can be done.
I do think that breaking apart and putting back together any functional unit repeatedly will lead to great benefits. Interestingly this is true not only of programming: writing instructors encoruage the same thing. You might write a whole draft of a paper, then you split it into it's parts, and split each part into paragraphs, and each paragraph into sentences. You can evaluate each sentence in isolation, improve, reword, and polish it to perfection. But then you put it back together and each element then has to be adjusted again to work as best as possible in the new setting. The perfect introduction, the perfect body, and the perfect conclusion would make a horrible paper if they were just slammed together - they need to be woven together and each must adjust to the others.
So (my philosophy only), unit testing and decoupling are great tools to dissect your code and find better ways of doing things, but one should not forget that in the end the goal is to write one streamlined elegant program: one unit.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
No I just thought that someone with your programming skills and your opinion about the optimize later page has heard at least a little about this toppic. (Thats not an accusation that you should have.)
It's about not throwing away those printlines. But never mind I do it every day.
Think of it like you had another button next to the spell checker (aka compiler). After you defined the content of each paragraph you can press this button to ensure that every paragraph follows his definition (aka run the unit tests). This should give you big freedom to adjust them to the others.
Of course you should not compile the test routines in to the productive code.
But hey you are doing great with your philosophy. Lets say you are KISS
Your Pictures are great, are you a writer?
You say formal, are you a mathematician? You say education: They never looked at our Java code and the most important thing I learnd is to never ever use Open Source. I slaped them in the face. Then I was on the run when I heard your nifty little song. I sit down next to you to listen a bit. And since I am stoned I only recognise it now that I play this crazy funky formal rhythms.
Offline
[Off Topic]
Ha, thanks for the comments.
For my day job I do teach a university writing course for psychology students while I'm working on my dissertation in neuroscience and behavior. I'm not much of a neuroscientist though, and the type of behavior that I study has really lost momentum (and funding) in the American universities.
I have found, though, that I can combine my knowledge of behavioral research with my hobby of programming and build and program testing equipment for research laboratories. I'm doing this 'off the books' now and my equipment is being used in several labs here. I plan on making more of a business of it once I finish my dissertation work.
By using open source software, and some of the new toys in "open source hardware"[1], I can make flexible useful equipment for tens of dollars when the current comercially available counterparts cost hundreds of thousands of dollars.
[1]: I put open-source hardware in quotes as I'm skeptical as to how well the term can apply to hardware - but people have started using this term, and I like what they are producing.
[/Off Topic]
Last edited by Trilby (2012-11-26 16:04:00)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Floating layer
I finally got so irritated with a couple transient windows being tiled that I implemented a floating layer just for these transient (eg dialog) windows. It turns out it was quite easy and did not add much code nor resource use. Further, it only took a couple minor additions to have the floating layer available for any window.
So now ttwm has a proper floating layer. Pull a window into floating by MOD+mouse drag to move (left button) or resize (right button). Push back into tiling by Mod+middle mouse button.
The biggest challenge was figuring out a focus model that does something reasonable with focus when the currently focused window is closed. Currently focus goes to the next window in the same stack if there is one (each desktop has a tiled stack and a floating stack), If there is no next window, focus goes to the top of the tiling stack, or if there are not tiled windows it goes to the top of the floating stack.
Improved external monitor support coming soon
The changes made to do this may actually make ttwm *lighter*. As is often the case the more general solutions are often more efficient. This change caused me to implement some more general solutions in the code. As a by product of these general solutions I've realized I can turn ttwm's currently very limited external monitor support into a full or proper support so the external monitor can have it's own tiled stack of windows and it's own floating stack.
I anticipate the changes to the external monitor support by year end. Then after some major code clean up to remove some kludge-buildup I may start preparations for a v2.0 tarball release with anticipated testing in the first quarter of the year with a ~Apr 2013 release of the 2.0 tarball if all goes well.
v2.0 coming ~Apr 2013
If anyone wants to prepare patches for a 2.0 version I'd encourage them to wait until the end of January as I anticipate major code changes until then, but hopefully from then to Apr the code changes should be limited to bug fixes. Also, if anyone (doomicide?*) has patches they'd like to be considered for incorporation into v2.0 please let me know.
Intended changes for 2.0 from 1.0:
- tabbar can be hidden/showed, or moved from top/bottom at run-time
- floating layer (not a separate mode, just a layer)
- full external/second monitor support, I also anticipate independent workspace switching on each monitor.
- some generalized solutions in code may streamline many parts of the code
- goal of keeping this all below 800 lines of code*
*lines-of-code is not a good metric for actual resource use - so in any case where more lines could be more efficient, I'll go with more lines. Just the same, I strive for keeping the code simple as well.
---------
FLOATING FYI: As there are no window borders, if you have terminals (or any windows with the same background color) floating over other terminals, it can be rather hard to tell where one window ends and another begins.
*PATCHES: I see banish and window rules are the current patches on doomicide's github. Banish will not be included but can be acheived with a binding to call iocane. Rules may be considered - I'm not keen on them myself, but if users use them they could be done.
ADDED BONUS: this floating layer allowed for not passing the focus to transient dialog windows. This solves the previous firefox download dialog issue once and for all.
Last edited by Trilby (2012-12-08 01:47:30)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Just messing around with the changes this AM and I'm not getting the firefox download window working properly. See here:
Now I don't have OK or Cancel buttons and mod+Print doesn't work to refocus the window anymore.
Just had a chance to play around with this a little more and I don't appear to have any floating layer support. That little dialog box that pops up in the left upper corner of firefox for downloads can't be moved either. If you killclient firefox closes first and then the dialog box closes when you killclient again. I've tried a few other apps like terminals or gimp and I don't seem to have any floating layer.
Last edited by bgc1954 (2012-12-08 20:30:14)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Have you tried moving or resizing the window with MOD+mouse?
The firefox dialog, I've found, remembers it's previous size, so it starts up at whatever size it last recorded. I resized mine once, and from then on it showed up at the proper size.
Can you move/resize windows at all? This ability is not new - the only part that is new is that ttwm "remembers" where moved/resized windows have been placed when you switch between workspaces or open new windows. The MOD+mousebutton behavior has been around from the beginning.
Last edited by Trilby (2012-12-08 21:48:31)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
@Trilby - Yes, I have tried moving and resizing but it doesn't work for me. I tried installing an older version of ttwm--built 20121110--that I had in a backup directory and it seems I can't move with mod+mouse in that version either, although I'm sure I could at one point. I wouldn't likely notice that since I next to never move or resize windows.
I also get that little window in the upper left when I try to open a new folder in bookmarks, with firefox, but all I can do there is cancel since there are no other buttons and it won't take the focus to name the new folder. I can't resize the little boxes either.
Like I said in my last post, I tried out gimp as I thought that would be a handy app to be able to move around windows but I can't move or resize anything there either. I'm not sure what to try to troubleshoot this at this end?
Last edited by bgc1954 (2012-12-09 03:08:45)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Do you get any errors or messages on the stdout (tty1 if you use xinit/startx from there)?
I just pushed a "verbose" button press function to git. You could try the current git and make sure the stderr output (again to tty1) sends two messages with every mod+mousebutton press.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Actually, I use xdm to login--remember the problems that caused?
I built new git version, then disabled the xdm.service and rebooted but tty1 just stops at "Reached graphical interface" and sits there. I can change to tty2 and startx but when I quit ttwm after trying mod+mouse buttons, I don't get any errors. I'm likely doing something wrong. I haven't used startx or xint since way before systemd times.
Last edited by bgc1954 (2012-12-09 05:01:11)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
With X's new default configs you wouldn't actually get to see any of the output. You'd need to tell X to start on a separate tty.
If your xdm session is shut down you could go to tty2 and run `xinit -- vt3` which will launch X on tty3 while leaving the stderr output visible on tty2.
Alternately, even with a current xdm session (and x) running, you can start a second X session by going to any free tty and running `xinit -- :1 vtN` where N is yet another free virtual terminal.
There should also be a way to monitor the stderr from X when using xdm - it may create a log file.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Well, that works, but strangely. I use xinit --vt3 from tty2 and X starts but on tty1--WTF! I check tty2 but no errors reported when trying out mod+mouse buttons. I'm starting to feel like a damned newbie--no offense, newbies.
edit: Just for s**** & giggles, I built the new version on my netbook and I can't move or resize anything there either. No errors using the above procedure. That's it, I'm going to bed...zzz
Last edited by bgc1954 (2012-12-09 05:48:52)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Are there no messages at all when you use Mod+mousebutton? If not then it's not even detecting the button press at all. (edit: I've now removed these verbose messages)
EDIT: I think I figured it out. I suspect you have a lock key (eg Numlock) on right? I got the keybindings working with lock keys a while back, but I never bothered with the mouse binding. I'll start working on that fix, but if you could confirm that that's the only issue that'd be great.
EDIT: That was an easy fix. If that was your issue the current git version should fix it.
Last edited by Trilby (2012-12-09 13:44:34)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Eureka! That was it.
As soon as I turned off numlock everything functions as it should. Thx, I'm glad it didn't turn out to be a big deal. I've just got a couple of errands to run and then I'll build the new git version and see how it behaves with numlock. I'm sure it will all be fine. Thx again, Trilby.
I can now resize the dialog window from firefox but if I try to add a new folder to bookmarks, I can move and resize the dialog window but I can't rename the folder as the text box never gets highlighted to allow text entry. I don't know if the new git version will do anything for this but I'll let you know.
Edit: I'll have to investigate further with my netbook as it has no numlock key and move/resize wasn't working there last night. Oh bother.
Last edited by bgc1954 (2012-12-09 15:36:34)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Both numlock and capslock would have previously interfered with the mouse bindings - but they should both be fine now.
There are some minor quirks yet with setting input focus for dialog windows - this is probably behind the text box issue you describe. I'll try to replicate that and investigate further. EDIT: I found the same behavior you describe. Now time to investigate. EDIT2: that was a ridiculously easy fix. I had some reason for not allowing transient windows to get input focus ... but I don't remember what it was. I've now allowed them to get focus when clicked, they just should not get focus when originally mapped (displayed).
BTW, reading back through this thread, I saw lighthearted comment you made about raising various issues. I just want to say thanks for taking the time to report such issues. Other "use cases" for ttwm that highlight issues I don't get to see on a daily basis are the only way to keep improving it. I appreciate all the time you've taken to report these issues.
Last edited by Trilby (2012-12-09 16:50:07)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Just built new git and I'm happy to report that everything is great on this end. And I was right, this new version is wonderful for working with gimp. Resize and move with all the gimp windows makes the whole apps usage much better. And I just love the middle mouse "undo/return" button. It's so much handier than having to resize your window back after you've resized it--if that makes any sense.
The netbook issue was just me being over-tired last night and totally forgetting the mod key with the touchpad... duhhh. The key combos there are quite awkward with the touchpad so, unless I plug in a mouse, I'll likely not do much resizing or moving on the netbook.
I had some reason for not allowing transient windows to get input focus ... but I don't remember what it was. I've now allowed them to get focus when clicked, they just should not get focus when originally mapped (displayed).
I think I remember an issue with firefox dialog not getting focus and you toyed with the idea, implemented a focus with mouse, and then went back to your original principle of having no mouse support in ttwm--so much for that
--and that's where we got the mod+Print to focus dialogs.
I've been happy to provide any and all help I can as ttwm has become my alltime favorite wm. Now, I can just continue experimenting with wm's but know that ttwm does everything I need it to do and has a developer that quickly irons out any of the quirks--or bugs--that I've ever come across. I appreciate your work on ttwm and all I've learned as a result of using it.
Hope I didn't swell your head so much that your "trilby" doesn't fit properly.
Last edited by bgc1954 (2012-12-09 17:32:34)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Just noticed a few glitches with the new mod+mouse focus/move--BTW mod+print doesn't seem to do anything anymore to refocus windows. I was moving some mp3 files from my PC to mp3 player using pcmanfm and I was getting a dialog box saying my player was full but I didn't know that until I focused the dialog with mod+mouse and it suddenly resized to fullscreen (monocle mode). Before I focused it, it was just an empty, small, grey box.
I also noticed another behavior with double-clicking on an mp3 file which pcmanfm opens with gnome-mplayer in my setup. Gnome-mplayer plays the file but the screen doesn't show what it's supposed to like a moving progress bar and displaying the name of the song until you mod+rt-mouse and actually move it. Just clicking on it with mod+rt-mouse didn't really do anything to focus it and it seemed to kind of freeze for a bit as I couldn't even move away and back with mod+arrow keys or mod+j/k.
Pcmanfm renaming a folder or file also brings up a dialog box but the text isn't highlighted blue until you click to focus and then the window goes fullscreen (monocle mode). Funny thing is that even though the text isn't highlighted blue before focus--it's grey--you can enter text to rename the folder or file and then click ok.
More grist for the mill.
Last edited by bgc1954 (2012-12-09 20:09:28)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
Oye, lots of grist there - my hat will definitely fit now!
I'm installing pcmanfm as that last behavior seems like it should be easiest to try to replicate.
Mod+print shouldn't do much - it just calls the stack function again. If there is no currently focused window it will set focus to the first tiled window, or the first floating window if there are no tiled windows. This is a very 'dumb' function, it just ensures that focus is set to some window on the current workspace.
So far I have not been able to replicate the issue with renaming files in pcmanfm, but I'll keep digging. Do you initiate renaming by the right-click context menu? When I do, the dialog pops up with input focus (input box is highlighted) and I can type a new name. (edit: same functional results with the F2 shortcut).
Last edited by Trilby (2012-12-09 20:53:40)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Yes, I use the right-click menu for renaming or deleting, etc. but the same behavior happens if I use F2. You're right, you get a box with the highlight in grey--normally pcmanfm gives you a blue highlighted box--but you can get the blue highlight by mod+lt-mouse click--I'm getting my right and left mixed up I think--and it looks as I expect. When this happens, if I'm in monocle mode, the dialog box resizes fullscreen and then the cancel button doesn't work unless you click on it and then away and back. The OK button works regardless. Maybe I'm just being picky as it works without touching it, just a different highlight color than I'm used to.
With firefox download dialog box, mine always comes up small and I have to resize with mod+rt-mouse click so the ok and cancel buttons appear. The resize doesn't seem to stick for each use.
I can see why you're not a big rodent fan as this new stuff seems to introduce more complication to the dialog boxes--but only if you mess with them like me.
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
I still can't replicate the pcmanfm behavior here - I'll try it on my work computer tomorrow.
I do get the same extra-small bookmarks dialog window in firefox. But this I can quite confidently blame of firefox. With these transient windows in the floating layer, ttwm never touches their geometry. That size is the size firefox sets.
The size "memory" I referred to earlier is not part of ttw, but I believe it is part of gtk-dialog windows. So if a gtk-file-dialog window is opened, resized, then closed, the next gtk-file-dialog window opened will open at the same size.
Firefox does not use gtk-dialogs as far as I can tell. I suspect they use their own XULRunner toolkit (though I know nothing about this except it's existence).
I supose I could check for WM size hints on transient windows and set the size manually. But that seems rather foolish. Whenever a program creates a window, it sets an initial size. Applications should allow window managers to resize windows, but they shouldn't depend on the WM to set the size. OK, firefox does depend on the WM to set the window size. Have I mentioned lately how much I dislike firefox? I have compensated for that and TTWM will check the size-hints of any transient window and set the size appropriately.
Last edited by Trilby (2012-12-10 00:17:37)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Have I mentioned lately how much I dislike firefox? I have compensated for that and TTWM will check the size-hints of any transient window and set the size appropriately.
Not lately, but your resize hints work well. I, myself, am starting to become less fond of my old favorite as it seems to be crashing on me at inopportune, totally random times. I've been starting to use midori more and more but it has its issues as well.
On my end the ok button on the firefox download dialog is greyed out but still works fine when you click on it--just saying.
BTW, my netbook shows the same kind of behaviors as I've described on my desktop.
Last edited by bgc1954 (2012-12-10 00:54:23)
Time is a great teacher, but unfortunately it kills all its pupils ... - Louis Hector Berlioz
Offline
I was being mostly facetious. I actually think the gecko rendering engine is the best available - but in an effort to be so "cross platform" mozilla has had too cut far to many corners on the rest of the code. I'd rather they make different browsers for different platforms ... then they could really have a winner.
Anyhow, my tinkering is done for the night. I might stay up all night working on such things - but my wireless solar powered keyboard that boast never needing replacement batteries needs replacement batteries. My backup keyboard is missing one third of the keys, with another third broken thanks to a parrot that shares my home. As the escape and F1 keys are non-functional, using vim is completely out, and changing VTs to relaunch X is difficult. So no more coding tonight.
Last edited by Trilby (2012-12-10 01:09:43)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline