Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
xosd clock, plain text clock dockapp
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
kgraehl
n00b
n00b


Joined: 13 Sep 2003
Posts: 54

PostPosted: Fri Dec 19, 2003 10:51 pm    Post subject: xosd clock, plain text clock dockapp Reply with quote

I was searching all over for a simple way to have a clock always in the corner of my screen and ended up hacking up this silly thing using xosd, a simple library (you can find it in portage) that simply displays text on the screen, much like the volume or channel number on a television.

I'm a FVWM user and like the inherent simplicity. I thought I'd share with the forum because it's always nice to find little goodies here. Oh, and this also reads /proc/apm and displays the battery percentage because I have a laptop. It doesn't show the percentage if it's 100% Anyway, if you want to try this run gcc -lxosd clock.c -o clock

Code:

#include <stdio.h>
#include <string.h>
#include <xosd.h>
#include <unistd.h>
#include <time.h>

int main (int argc, char *argv[]) {
   time_t *t = NULL;
   xosd *osd;
   osd = xosd_create (2);
   if (!osd) {
      perror ("Error initializing osd\n");
      return 1;
   }
   xosd_set_font(osd, "-misc-fixed-medium-r-semicondensed-*-*-120-*-*-c-*-iso8859-15");
   xosd_set_outline_offset (osd, 1);
   xosd_set_outline_colour(osd, "Black");
   xosd_set_colour (osd, "White");
   xosd_set_pos (osd, XOSD_bottom);
   xosd_set_vertical_offset (osd, 2);
   xosd_set_align (osd, XOSD_left);
   xosd_set_horizontal_offset (osd, -6);
   char output[255];
   char i[8];
   FILE* fp;
   char buf[64];
   while(1) {
   time_t curr_time = time(t);
   fp = fopen("/proc/apm", "r");
   while(fgets(buf, 64, fp) != NULL) {
      sscanf (buf,"%*s %*s %*s %*s %*s %*s %s %*s %*s\n",i);
      strftime(output, 255, "%H:%M", localtime(&curr_time));
      if(strcmp(i,"100%")) {
      strcpy(output,strcat(output," "));
      strcpy(output,strcat(output,i));
      }
      xosd_display (osd, 1, XOSD_string, output);
      sleep(60);
   }
   fclose(fp);
   }
   xosd_destroy (osd);
   return 0;
}
Back to top
View user's profile Send private message
floam
Veteran
Veteran


Joined: 27 Oct 2002
Posts: 1067
Location: Vancouver, WA USA

PostPosted: Sat Dec 20, 2003 12:46 am    Post subject: Reply with quote

Hmm, I think it'd be cool if stuff like uptime and cpu resources could be shown on xosd using something like this as well, since gkrellm is kinda clunky for my tastes. Would it be too tricky for one to add stuff like that to this?
_________________
Think about your breathing.
http://floam.sh.nu
Back to top
View user's profile Send private message
kgraehl
n00b
n00b


Joined: 13 Sep 2003
Posts: 54

PostPosted: Sat Dec 20, 2003 7:25 am    Post subject: Reply with quote

shouldn't be too hard (though I don't know how to do this)
Code:

~/ uptime
 07:55:17 up 17:19,  3 users,  load average: 0.07, 0.03, 0.01


the c function scanf can read that in and access the number after the up like so (i think) and put it into a character array uptime.

Code:

sscanf (buf,"%*s %*s %s, %*s %*s %*s %*s %*s %*s %*s\n",uptime);


But I don't know how to get a command line output into the buf. (Note: this is my first c program). I'm sure one can write such a program in three lines in python or whatnot.

:)
Back to top
View user's profile Send private message
dna42
n00b
n00b


Joined: 26 Feb 2003
Posts: 72

PostPosted: Sat Dec 20, 2003 4:25 pm    Post subject: Reply with quote

you can read uptime from /proc/uptime
Quote:
uptime This file contains two numbers: the uptime of the system (sec-
onds), and the amount of time spent in idle process (seconds).
Back to top
View user's profile Send private message
FormerSlacker
Guru
Guru


Joined: 11 Mar 2003
Posts: 340
Location: Toronto, ON. Canada

PostPosted: Sat Dec 20, 2003 10:53 pm    Post subject: Reply with quote

The function you are looking for is popen():

FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);

Basiclly popen runs a process and the output of that process is readable on the stream that popen returns.

kgraehl wrote:
shouldn't be too hard (though I don't know how to do this)
Code:

~/ uptime
 07:55:17 up 17:19,  3 users,  load average: 0.07, 0.03, 0.01


the c function scanf can read that in and access the number after the up like so (i think) and put it into a character array uptime.

Code:

sscanf (buf,"%*s %*s %s, %*s %*s %*s %*s %*s %*s %*s\n",uptime);


But I don't know how to get a command line output into the buf. (Note: this is my first c program). I'm sure one can write such a program in three lines in python or whatnot.

:)
Back to top
View user's profile Send private message
ett_gramse_nap
Apprentice
Apprentice


Joined: 01 Oct 2003
Posts: 252
Location: Göteborg, Sweden

PostPosted: Mon Jan 12, 2004 8:27 pm    Post subject: Reply with quote

Is there a way to make the clock always-on-top? Every other application executed after the clock are put above it... dull! :(
_________________
Don't bother!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum