You are not logged in.

#51 2012-11-09 11:43:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] A DWM statusbar in C

As I have zero formal training in programming I was not familiar with the term "observer design pattern".  I did a quick search to learn a little about it.  If I am understanding the concept correctly, I'm pretty sure that's what Unia did with the wifi information: the main loop (observer) reads from the local record of wifi information every time it updates, but this local record of wifi information changes at a much slower rate because reading and setting it is costly and it is not that 'dynamic' of data.

I looked at your code.  I haven't tried it yet, but it looks quite similar to unia's version and nothing problematic jumps out at me.  I don't know why this would consume a lot of cpu - I doubt this is a problem with the loop itself and there is some other 'bug' somewhere.

I've used my version of two pretty low powered computers regularly (one intel atom netbook, and one rather old white imac with an intel core 2), neither cpu use nore memory every get high enough in either of these machines to even register at 0.1% in htop - and I used usleep to loop every half second.  I even had a version looping every 200ms and cpu use was still below 1%.

What kind of hardware are you running?

I'll test out your code later today to see if anything jumps out as a possible cause, but with a 5 second interval, this should not use any notable cpu resources.

EDIT:
If there is need to optimize changing out sprintfs for simpler string functions whenever possible, and changing out string functions for direct manipulation of array elements when practical might help.  But if you are getting even measurable cpu use with a 5 second interval, that suggests there is something more basic wrong with the code rather than needing such fine scale adjusting.

EDIT:
I just tested the code you posted, only adjusting a couple file name defintions for my system and it worked well.  I adjusted INTERVAL down to 1 and it never even registered in htop as 0.1%  cpu use.  Then I switched out sleep for usleep and went all the way down to looping every 50ms.  I had to adjust the conditional for the wifi check up a bit, but still looping every 50ms it was below 0.1% cpu use (on my intel core 2 imac).  This did "spike" up to 0.7% cpu use whenever the wifi was polled.

What kind of cpu use are you getting?

Last edited by Trilby (2012-11-09 12:08:34)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#52 2012-11-09 15:44:49

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Trilby could you look at my email again? tongue


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#53 2012-11-10 09:58:03

domac
Member
Registered: 2012-08-06
Posts: 102

Re: [SOLVED] A DWM statusbar in C

Hey Trilby, thanks for that comprehensive help!

My /proc/cpuinfo: http://sprunge.us/BBcQ?bash
and uname -a gives: http://sprunge.us/aJhF?bash

I'll do some more testings.
Cheers :-)

EDIT: I checked the CPU via htop… it is low. So the battery drain seems to come from something elsewhere. :-( and :-) Glad that dwm-bar is so over-the-top! Thanks.

Last edited by domac (2012-11-10 09:59:00)


domac [ git ]

Offline

#54 2012-12-13 13:19:10

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

So, I just added Audacious music player support and decided I'd let the user choose whether they want MPD support, Audacious support or nothing at all. I looked at how DWM lets you do this for Xinerama and implemented this in the same way. However, when I choose either MPD or Audacious and start playing a song, my WiFi information dissapears from the statusbar. When I compile with no music player support, it runs as expected. I suspect somehow it fails to handle the #ifdef parts, or something in the Makefile.

Can someone with more experience give me some pointers?

Here's my Makefile:

PROG     =  dwmst
PREFIX   =  /usr/local

# MPD, comment if you don't want it
MPDLIB   =  -lmpdclient
MPDFLAG  =  -DMPD

# AUDACIOUS, comment if you don't want it
#AUDLIB	 =  -ldbus-glib-1 -lglib-2.0 -laudclient
#AUDFLAG  =  -DAUD

LIBS     =  -liw -lasound -lX11 ${MPDLIB} ${AUDLIB}
CPPFLAGS =  ${MPDFLAG} ${AUDFLAG}
CFLAGS   =  -Os -Wall -Wno-unused-parameter -Wno-unused-result ${CPPFLAGS}


$(PROG): $(PROG).c
	@$(CC) $(CFLAGS) $(LIBS) -o $(PROG) $(PROG).c
	@strip $(PROG)

clean:
	rm -f $(PROG)

And the code:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <locale.h>
#include <alsa/asoundlib.h>
#include <X11/Xlib.h>
#include <iwlib.h>
#ifdef MPD
#include <mpd/client.h>
#endif /*MPD */
#ifdef AUD
#include <audacious/dbus.h>
#endif /* AUD*/

#define WIFI			"wlan0"		// Wireless interface
#define BATT_LOW		11			// Below BATT_LOW percentage left on battery, the battery display turns red
#define INTERVAL		1			// Sleeps for INTERVAL seconds between updates
#define VOL_CH			"Master"	// Channel to watch for volume
// Files read for system info:
#define BATT_NOW		"/sys/class/power_supply/BAT0/charge_now"
#define BATT_FULL		"/sys/class/power_supply/BAT0/charge_full"
#define BATT_STAT		"/sys/class/power_supply/BAT0/status"
// Display format strings. Defaults make extensive use of escape characters for colors which require colorstatus patch.
#ifdef MPD
#define MPD_STR			"%s \x02-\x01 %s   \x02•\x01   "					// MPD, playing
#define MPD_P_STR		"Pauze\x02:\x01 %s \x02-\x01 %s   \x02•\x01   "	// MPD, paused
#define MPD_S_STR		" "											// MPD, stopped
#define NO_MPD_STR		"Geen verbinding    \x02•\x01   "					// MPD, can't connect
#endif /*MPD */
#ifdef AUD
#define MUSIC_STR		"%s   \x02•\x01   "							// Music, playing
#define MUSIC_P_STR		"Paused\x02:\x01 %s   \x02•\x01   "			// Music, paused
#define MUSIC_S_STR		" "											// Music, stopped
#define NO_MUSIC_STR	"Geen verbinding    \x02•\x01   "			// Music, can't connect
#endif /* AUD*/
#define WIFI_STR		" %s %d%%   "								// WIFI
#define NO_WIFI_STR		"  Geen verbinding   "						// WIFI, no connection
#define VOL_STR			"\x02•\x01   %d%%   "						// Volume
#define VOL_MUTE_STR	"\x02•\x01       ×       "					// Volume, muted
#define BAT_STR			"\x02•\x01   D %d%%   "						// Battery, BAT, above BATT_LOW percentage
#define BAT_LOW_STR		"\x02•\x03   D %d%%   "						// Battery, BAT, below BATT_LOW percentage
#define BAT_FULL_STR	"\x02•\x04   F \x01%d%%   "					// Battery, full
#define BAT_CHRG_STR	"\x02•\x01   C %d%%   "						// Battery, AC
#define DATE_TIME_STR	"\x02•\x01   %a %d %b\x02,\x01 %H:%M   "	// This is a strftime format string which is passed localtime

int main() {
	Display *dpy;
	Window root;
	int num, skfd, loops = 60, mute = 0, realvol = 0;
	long lnum1, lnum2, vol = 0, max = 0, min = 0;
	char statnext[30], status[100], wifiString[30];
	struct wireless_info *winfo;
	winfo = (struct wireless_info *) malloc(sizeof(struct wireless_info));
	memset(winfo, 0, sizeof(struct wireless_info));
	time_t current;
	FILE *infile;
#ifdef MPD
	struct mpd_song * song = NULL;
	const char * title = NULL;
	const char * artist = NULL;
#endif /*MPD */
#ifdef AUD
	gint playpos;
	gchar *psong;
	DBusGProxy *session = NULL;
	DBusGConnection *connection = NULL;
	session = 0;
	psong = NULL;
#endif /* AUD*/
	// Setup X display and root window id:
	dpy=XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "ERROR: could not open display\n");
		exit(1);
	}
	root = XRootWindow(dpy,DefaultScreen(dpy));
	setlocale(LC_ALL, "");
// MAIN LOOP STARTS HERE
	for (;;) {
		status[0]='\0';
#ifdef MPD
		struct mpd_connection * conn = mpd_connection_new(NULL, 0, 30000);
		if (mpd_connection_get_error(conn))
			sprintf(statnext,NO_MPD_STR);

		mpd_command_list_begin(conn, true);
		mpd_send_status(conn);
		mpd_send_current_song(conn);
		mpd_command_list_end(conn);

		struct mpd_status* theStatus = mpd_recv_status(conn);
			if (!theStatus)
				sprintf(statnext,NO_MPD_STR);
			else
				if (mpd_status_get_state(theStatus) == MPD_STATE_PLAY) {
					mpd_response_next(conn);
					song = mpd_recv_song(conn);
					title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
					artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
					sprintf(statnext,MPD_STR,title,artist);
					mpd_song_free(song);
				}
				else if (mpd_status_get_state(theStatus) == MPD_STATE_PAUSE) {
					mpd_response_next(conn);
					song = mpd_recv_song(conn);
					title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
					artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
					sprintf(statnext,MPD_P_STR,title,artist);
					mpd_song_free(song);
				}
				else if (mpd_status_get_state(theStatus) == MPD_STATE_STOP) {
					sprintf(statnext,MPD_S_STR);
				}
		mpd_response_finish(conn);
		mpd_connection_free(conn);
		strcat(status,statnext);
#endif /*MPD */
#ifdef AUD
		g_type_init();
		connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
		session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE, AUDACIOUS_DBUS_PATH, AUDACIOUS_DBUS_INTERFACE);
		playpos = audacious_remote_get_playlist_pos(session);
		psong = audacious_remote_get_playlist_title(session, playpos);
		if (psong) {
			if (audacious_remote_is_paused(session)) {
				sprintf(statnext,MUSIC_P_STR,psong);
				g_free(psong);
				psong = NULL;
			} else if (audacious_remote_is_playing(session)) {
				sprintf(statnext,MUSIC_STR,psong);
				g_free(psong);
				psong = NULL;
			} else {
				sprintf(statnext,MUSIC_S_STR);
			}
		} else {
			sprintf(statnext,MUSIC_S_STR);
		}
		g_object_unref(session);
		session = NULL;
		strcat(status,statnext);
#endif /* AUD*/
	// WIFI
		if (++loops > 60) {
			loops=0;
			skfd = iw_sockets_open();
			if (iw_get_basic_config(skfd, WIFI, &(winfo->b)) > -1) {
				if (iw_get_stats(skfd, WIFI, &(winfo->stats), // set present winfo variables
					&winfo->range, winfo->has_range) >= 0) {
					winfo->has_stats = 1;
				}
				if (iw_get_range_info(skfd, WIFI, &(winfo->range)) >= 0) { // set present winfo variables
					winfo->has_range = 1;
				}
				if (winfo->b.has_essid) {
					if (winfo->b.essid_on) {
						sprintf(wifiString,WIFI_STR,winfo->b.essid,(winfo->stats.qual.qual*100)/winfo->range.max_qual.qual);
					} else {
						sprintf(wifiString,NO_WIFI_STR);
					}
				}
			}
			iw_sockets_close(skfd);
			fflush(stdout);
			memset(winfo, 0, sizeof(struct wireless_info));
		}
		strcat(status,wifiString);
	// Audio volume
		snd_mixer_t *handle; // init alsa
		snd_mixer_open(&handle, 0);
		snd_mixer_attach(handle, "default");
		snd_mixer_selem_register(handle, NULL, NULL);
		snd_mixer_load(handle);
		snd_mixer_selem_id_t *vol_info; // init channel with volume info
		snd_mixer_selem_id_malloc(&vol_info);
		snd_mixer_selem_id_set_name(vol_info, VOL_CH);
		snd_mixer_elem_t* pcm_mixer = snd_mixer_find_selem(handle, vol_info);
		snd_mixer_selem_get_playback_volume_range(pcm_mixer, &min, &max); // get volume
		snd_mixer_selem_get_playback_volume(pcm_mixer, SND_MIXER_SCHN_MONO, &vol);
		snd_mixer_selem_id_t *mute_info; // init channel with mute info
		snd_mixer_selem_id_malloc(&mute_info);
		snd_mixer_selem_id_set_name(mute_info, VOL_CH);
		snd_mixer_elem_t* mas_mixer = snd_mixer_find_selem(handle, mute_info);
		snd_mixer_selem_get_playback_switch(mas_mixer, SND_MIXER_SCHN_MONO, &mute); // get mute state

		if(mute == 0)
			sprintf(statnext, VOL_MUTE_STR);
		else
			realvol = (vol*100)/max;
			sprintf(statnext, VOL_STR, realvol);

		if(vol_info)
			snd_mixer_selem_id_free(vol_info);
		if (mute_info)
			snd_mixer_selem_id_free(mute_info);
		if (handle)
			snd_mixer_close(handle);
		strcat(status,statnext);
	// Power / Battery
		infile = fopen(BATT_NOW,"r");
			fscanf(infile,"%ld\n",&lnum1); fclose(infile);
		infile = fopen(BATT_FULL,"r");
			fscanf(infile,"%ld\n",&lnum2); fclose(infile);
		infile = fopen(BATT_STAT,"r");
			fscanf(infile,"%s\n",statnext); fclose(infile);
		num = lnum1*100/lnum2;
		if (strncmp(statnext,"Charging",8) == 0) {
			sprintf(statnext,BAT_CHRG_STR,num);
		}
		else if (strncmp(statnext,"Full",8) == 0) {
				sprintf(statnext,BAT_FULL_STR,num);
		}
		else {
			if (num <  BATT_LOW)
				sprintf(statnext,BAT_LOW_STR,num);
			else
				sprintf(statnext,BAT_STR,num);
		}
		strcat(status,statnext);
	// Time
		time(&current);
		strftime(statnext,38,DATE_TIME_STR,localtime(&current));
		strcat(status,statnext);
	// Set root name
		XStoreName(dpy,root,status);
		XFlush(dpy);
		sleep(INTERVAL);
	}
// NEXT LINES SHOULD NEVER EXECUTE, only here to satisfy Trilby's O.C.D. ;)
	XCloseDisplay(dpy);
	return 0;
}

(Sorry, gist is not working here) Also, the Audacious libs are currently not working. Before, I used pkg-config to find the libs and I'm now (for consistency) trying to drop that. Not sure whether it's possible (or smart) but you should use MPD to test.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#55 2012-12-15 12:16:36

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Anyone?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#56 2012-12-15 13:49:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] A DWM statusbar in C

As I'm not remotely familiar with either of those two music systems, I have no idea what kind of data they give.  So the first step I'd take is to replace to strcat() functions in the music player sections with strncat().  Put a pretty small N, so it will cut off any long string which could be pushing your other status information off the end.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#57 2012-12-15 13:53:00

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Trilby wrote:

As I'm not remotely familiar with either of those two music systems, I have no idea what kind of data they give.  So the first step I'd take is to replace to strcat() functions in the music player sections with strncat().  Put a pretty small N, so it will cut off any long string which could be pushing your other status information off the end.

The functions themselves work fine if I just use either one of them and remove the other from the code completely. My GitHub currently hosts two dwmstatuses: one for MPD and one for Audacious. Both work correctly when compiled. (GitHub: https://github.com/Unia/dwmst)

It's just when I combine both of them into one and make the user choose on compile-time which player they want to support, it works incorrectly.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#58 2012-12-15 21:34:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] A DWM statusbar in C

I only see the code for either one of your git, are they combined anywhere there?  In any case, my recommendation still stands, have you tried it?

On a (probably) unrelated note, you don't need to call g_type_init in the loop - and you probably shouldn't.  Call it once when the program starts, not repeatedly every time through the loop.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#59 2012-12-15 23:02:00

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Trilby wrote:

I only see the code for either one of your git, are they combined anywhere there?  In any case, my recommendation still stands, have you tried it?

Sorry, the combined version is not available on my GitHub yet. I did post the code a couple of posts up (because Gist isn't working for me)

Trilby wrote:

On a (probably) unrelated note, you don't need to call g_type_init in the loop - and you probably shouldn't.  Call it once when the program starts, not repeatedly every time through the loop.

Yea, I need to double check the Audacious function. I don't need to call it every second either, so I'm thinking of doing the same as I did with the WiFi function. Thanks for the pointer! I will also look into your suggestion wink


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#60 2012-12-16 07:05:51

Loomx
Member
Registered: 2012-12-16
Posts: 1

Re: [SOLVED] A DWM statusbar in C

Greetings.

I'm going to jump in here and add my thanks to Trilby for his dwmstatus script.
A while ago I was trying to get my head around a statusbar written in C, and Trilby's was the clearest and most logical one I could find, so I used it as the basis for mine.

I especially liked the use of a file to store the alsa_volume level, so I used a similar idea to display the currently playing track name (from mplayer), although it took a bit of reading and experimenting before it would display correctly (and there's still a bit of a hack in the code).

Here's mine; cheers smile

/*
 * Compile with:
 * gcc -Wall -pedantic -std=c99 -lX11 dwmstatus.c -o dwmstatus
 */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <X11/Xlib.h>

/* Files read for system info: */
#define TRACK_FILE      "/home/jonny/.mp_track"
#define MEM_FILE        "/proc/meminfo"
#define VOL_FILE        "/home/jonny/.alsa_volume"
#define BATT_NOW        "/sys/class/power_supply/BAT0/energy_now"
#define BATT_FULL       "/sys/class/power_supply/BAT0/energy_full"

/* Display format strings: */
#define TRACK_STR       "%s| "
#define MEM_STR         "%ldMB | "
#define VOL_STR         "%ddB | "
#define BATT_STR        "±%ld%% | "
#define TIME_STR        "%H:%M"

int
main(void) {
    Display *dpy;
    int num;
    long lnum1, lnum2, lnum3, lnum4;
    char track[30], statnext[30], status[100];
    time_t current;
    FILE *fp;

    /* Setup X display */
    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "ERROR: could not open display\n");
        exit(1);
    }

/* MAIN LOOP STARTS HERE: */
    for (;;sleep(1)) {
        status[0]='\0';

    /* Track */
        if ((fp = fopen(TRACK_FILE, "r"))) {
            fgets(track, sizeof(track), fp);
            track[strlen(track)-1] = ' ';
            fclose(fp);
            sprintf(statnext, TRACK_STR, track);
            strcat(status, statnext);
        }

    /* Memory */
        if ((fp = fopen(MEM_FILE, "r"))) {
            fscanf(fp, "MemTotal: %ld kB\nMemFree: %ld kB\nBuffers: %ld kB\nCached: %ld kB\n", &lnum1, &lnum2, &lnum3, &lnum4);
            fclose(fp);
            sprintf(statnext, MEM_STR, (lnum1-(lnum2+lnum3+lnum4))/1024);
            strcat(status, statnext);
        }

    /* Volume */
        if ((fp = fopen(VOL_FILE, "r"))) {
            fscanf(fp, "%d", &num);
            fclose(fp);
            sprintf(statnext, VOL_STR, num);
            strcat(status, statnext);
        }

    /* Battery */
        if ((fp = fopen(BATT_NOW, "r"))) {
            fscanf(fp, "%ld\n", &lnum1);
            fclose(fp);
            fp = fopen(BATT_FULL, "r");
            fscanf(fp, "%ld\n", &lnum2);
            fclose(fp);
            sprintf(statnext, BATT_STR, (lnum1/(lnum2/100)));
            strcat(status, statnext);
        }

    /* Time */
        time(&current);
        strftime(statnext, 38, TIME_STR, localtime(&current));
        strcat(status, statnext);

    /* Set root name */
	XStoreName(dpy, DefaultRootWindow(dpy), status);
	XSync(dpy, False);
    }

/* NEXT LINES SHOULD NEVER EXECUTE */
    XCloseDisplay(dpy);
    return 0;
}

Offline

#61 2012-12-19 00:01:28

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

I solved everything smile I didn't allow status enough memory/bites, upgrading [30] to [100] (random guess) fixed it. I might try decreasing it in the future, but [100] is ok with me. I don't have Trilby's O.C.D big_smile

Also, I implemented a check to see if Skype is running. This gave me the ability to drop the system tray from DWM which gave me quite a few headaches trying to modify. Other stuff is on the TODO list, see my GitHub for that (also for intrucstions on how to make the new dwmst)

Thanks again everyone!


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#62 2013-06-02 16:29:22

grobar87
Member
From: Македонија
Registered: 2010-08-25
Posts: 172

Re: [SOLVED] A DWM statusbar in C

Hi,
I like your statusbar and i want to use it big_smile So i installed following your instructions in readme file,then i enable systemd service file but i can't autostart statusbar on boot.Should i put something in xinitrc file?
Thanks.


And... here... we... go!

Offline

#63 2013-06-02 17:47:07

grobar87
Member
From: Македонија
Registered: 2010-08-25
Posts: 172

Re: [SOLVED] A DWM statusbar in C

I solved! I just put "dwmst &" in xinitrc and it works.


And... here... we... go!

Offline

#64 2013-06-02 18:08:03

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Yes, the service file is only to restart dwmst after suspend/sleep because it stops working then. However, it doesn't work in most cases for me so I should look I into it.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#65 2013-06-02 18:57:13

grobar87
Member
From: Македонија
Registered: 2010-08-25
Posts: 172

Re: [SOLVED] A DWM statusbar in C

Doesn't work for me either. After suspend i restart service then start dwmst again to work. And how to remove this strange sings?http://i.imgur.com/9ccAUvE.jpg
Btw i don't use mpd or audacious and have commented out that lines in makefile like you said in readme file, because with mpd i got some errors when i run "make".I installed all dependencies.

Last edited by grobar87 (2013-06-02 19:04:06)


And... here... we... go!

Offline

#66 2013-06-02 19:04:35

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Eh, you did modify it to match you setup right? I mean, you're not from Holland so why use my Dutch in there. Also, if you don't use MPD or Audacious or Skype, simply remove everything from the code.

Last edited by Unia (2013-06-02 19:05:14)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#67 2013-06-02 19:17:13

grobar87
Member
From: Македонија
Registered: 2010-08-25
Posts: 172

Re: [SOLVED] A DWM statusbar in C

Of course i will modify later,still trying to make it works properly.I removed skype,audacious and mpd code but i'm not very good in C coding so that's the reason why i "steals" your setup.Sorry but i like it smile It's ok right? big_smile


And... here... we... go!

Offline

#68 2013-06-02 19:23:52

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

Yes it's why I put it online in the first place wink I would suggest removing code first and then fixing it, since you might also remove certain issues you would otherwise spend time on fixing that will be removed anyway.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#69 2013-06-02 21:14:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [SOLVED] A DWM statusbar in C

I suspect thinkering with these status input tools is a good way to learn C.  At their simplest they are not much more complex than a "Hello World" program, yet they do something functional that you will use all the time.

They also allow you to add more and more to it - you can learn about various kernel subsystems (power, audio, networking), and you can interact with other programs via libraries (the mpd and audacious stuff), all from a fairly simple code base.

But like other configs, I'd say it's handy to steal ideas, but don't just grab the code - start simple and build your own, that way it's not only just what you wanted, but you also get to learn from it ... and get to show off to anyone who looks at it and know that you built it yourself.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#70 2013-06-02 21:55:20

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: [SOLVED] A DWM statusbar in C

I never started from scratch either but took what you already had. Granted, your code was alot smaller than mine - which is why I suggested to remove code that you don't need.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#71 2013-06-03 09:44:10

grobar87
Member
From: Македонија
Registered: 2010-08-25
Posts: 172

Re: [SOLVED] A DWM statusbar in C

I completely agree with you guys,stealing your codes it's not a good idea for learning C but it's good starting point.I already start to build dwm by myself adding patches and stuff but i need some time to finish.It's not that easy for me i'm complete noob in C.


And... here... we... go!

Offline

Board footer

Powered by FluxBB