Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-15-2009, 08:14 PM   #1
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 243
Blog Entries: 2

Rep: Reputation: 41
Learning C while modifying dwm...

I decided to rewrite this out and use this thread for a reference as well as a place to receive any help/guidance (If anyone wishes to) while making modifications to dwm.

bstack.c (Jul. 17. 09)
bstack(Monitor *m) {
       int x, y, h, w, mh;
       unsigned int i, n;
       Client *c;

       for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
       if(n == 0)

       c = nexttiled(m->clients);
       mh = m->mfact * m->wh;
       resize(c, m->wx, m->wy, m->ww - 2 * c->bw, (n == 1 ? m->wh : mh) - 2 * c->bw, False);

       if(--n == 0) return;

       x = m->wx;
       y = (m->wy + mh > c->y + c->h) ? c->y + c->h + 2 * c->bw : m->wy + mh;
       w = m->ww / n;
       h = (m->wy + mh > c->y + c->h) ? m->wy + m->wh - y : m->wh - mh;
       if(h < bh)
               h = m->wh;

       for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
               resize(c, x, y, ((i + 1 == n) ? m->wx + m->ww - x : w) - 2 * c->bw,
                      h - 2 * c->bw, False);
               if(w != m->ww)
                       x = c->x + WIDTH(c);
P.S. I am writing this here for many reasons, the main reason is I have a bad habit of learning the wrong methods for doing a lot of things (regardless how many times I read books, etc) and since I am learning this all on my own, well, some helpful hints/reading/etc would be...well...helpful...

Anyway, if no one likes that I am doing this, just say so and I will ask a moderator to delete the thread. If you don't mind it, then thanks, ...

Last edited by Mol_Bolom; 07-27-2009 at 09:35 PM. Reason: Changing my method for learning C.
Old 07-27-2009, 09:46 PM   #2
Registered: Nov 2008
Location: S.W. Kansas
Distribution: Slackware64 14.0 / 14.2
Posts: 243
Blog Entries: 2

Original Poster
Rep: Reputation: 41
Next modification I made...

I added this bit of code to dwm.c
#include <sys/time.h>
#include <time.h>

struct timeval tv;
static time_t curtime;

	gettimeofday(&tv, NULL);
	curtime = tv.tv_sec;  
	strftime(stext, 256, "%d/%m %I:%M %p", localtime(&curtime));
And inside drawbar() I added settime(); right after the initialization of variables. So that whenever the bar is redrawn, the time will be displayed where dwm-5.6 would have normally been displayed. I don't really have a need to keep track of time down to the second, and since opening and closing a window is as simple as a few key presses, it seems to be more appropriate to change the time that way rather than adding extra code that serves no purpose, IMO.

The last thing I changed is I commented out strcpy() and removed the if statement.

updatestatus(void) {
//	if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)));
//		strcpy(stext, "dwm-"VERSION);

        gettextprop(root, XA_WM_NAME, stext, sizeof(stext));
So far I don't see any problems.

Last edited by Mol_Bolom; 07-27-2009 at 09:50 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] alias startdwm="export MYWM=dwm & startx" Mol_Bolom Programming 1 07-12-2009 02:21 AM
dwm Firefox pop-up menus SentralOrigin Linux - Desktop 2 03-26-2009 10:39 AM
Error in Perl Code : Bad switch statement(Problem in code block)? near ## line # suyog255 Programming 4 02-20-2008 05:35 PM
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration