Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 18 Dec 2017, 11:16
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
simple icon tray
Post new topic   Reply to topic View previous topic :: View next topic
Page 9 of 11 [160 Posts]   Goto page: Previous 1, 2, 3, ..., 7, 8, 9, 10, 11 Next
Author Message
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Sat 06 Dec 2014, 22:44    Post subject:  

Here is how to use gettext for tool-tips in C code (learned this from 01micko)

Define:
Code:
#define _(STRING)    gettext(STRING)


Function:
Code:
gtk_status_icon_set_tooltip(tray_icon, _("Refresh the Desktop"));

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Sun 07 Dec 2014, 01:31    Post subject: Re: sdesk Ubuntu  

torios wrote:
What is this licensed and who do I license it to?
right now (place holder info)
GPL3
Not only no, but hell no! All of my code here is released to the Public Domain (or equivalent CC0 or WTFPL or 0 clause BSD license)... with no warrantees of course. Feel free to relicense it however you want, but I would appreciate avoiding the GPL3+ if you can so that it may be used in low cost ROM based systems (the GPL3 "tivoization clause" prevents this legitimate use).
The latest version (sdesk) is all my original code and is basically just SIT with the addition of being able to set the background.
If you go through this thread, I have provided the basis for various example applets. Its not really hard considering about half of tray applets are just a static icon with some click actions like glipper and wpa_gui or a few that rarely change: volume control, battery, sven

Quote:
I don't know C, but only C++ so maybe now is a good time to learn C as well so I can make even lighter programs.
Thanks so much!!
Aside from memory management, casting and pointers, C is much easier. Usually the C compiler tells you almost exactly what/where you screwed up, whereas a C++ compile just says you F'd up somewhere. I put C++ and perl in a category I call "write-only languages"... it is much easier to read and follow other people's C code.

Edit:
Code:
<svg height="48" width="48" viewBox="0 0 100 100">
  <circle cx="0" cy="100" r="100" stroke="black" stroke-width="2" fill="blue" fill-opacity="0.3" />
  <circle cx="0" cy="100" r="75" stroke="black" stroke-width="3" fill="blue" fill-opacity="0.3" />
  <circle cx="0" cy="100" r="50" stroke="black" stroke-width="4" fill="blue" fill-opacity="0.3" />
  <circle cx="0" cy="100" r="25" stroke="black" stroke-width="5" fill="blue" fill-opacity="0.3" />
  <path d="M97,0L70,27L75,10L78,14,93,0" fill="blue" stroke="black" stroke-width="1" />
  <path d="M73,28L99,2L95,20L91,15,75,30" fill="blue" stroke="black" stroke-width="1" />
</svg>

this svg image can be easily adapted to replace wifi applets by using /proc/net/dev for receive and transmit arrows (the path elements) and /proc/net/wireless to show the signal level (the circle elements)

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Mon 08 Dec 2014, 23:39    Post subject: license  

Hi technosaurus,
would MIT be appropriate, then? Basically I want you to simply choose whatever license you want and tell me Smile
I used GPL3 because it is a standard GNU license... don't be offended Smile
I license a lot of stuff as MIT since it seems to be very free and permissive.

We are so fortunate to have legal protections for freedom of code Smile

I have been parsing the thread lately. So I will probably go over this a few times to get the full gist of everything, but suffice it to say, I am very excited about this program. I think this will be a huge help in making a lightweight version of Ubuntu (which is not known for being lightweight). I am confident that this will allow us to make a plethora of 'applets' available for the tray. Plus SVGs are amazing. Thanks for your work!

I will crack open the ' C a reference Manual ' on my shelf sometime soon
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Tue 09 Dec 2014, 09:58    Post subject:  

MIT is fine.

Here is some rather rudimentary low level C that avoids using printf, scanf and even malloc so the static binary is under 8kb.
Basically it monitors /proc/acpi/battery and generates an svg and tooltip text.

Code:
/*
 * proc2imgd.c
 *
 * Copyright 2014 Brad Conroy - released to public domain
 *
 */
#include <fcntl.h> //open
#include <unistd.h> //read,write
#include <string.h> //strstr, strlen
#include <stdlib.h> //getenv
#include <sys/stat.h> //mkdir

#define strcpyALL(buf, l, ...) do{ \
   char *bp=(char*)(buf); \
   const char *s, *a[] = { __VA_ARGS__,NULL}, **ss=a; \
   while((s=*ss++)) \
      while((*s)&&((--l) >0)) \
         *bp++=*s++; \
   *bp=0; \
}while(0)

static inline int ispad(int X){return (X)==' '||(unsigned)(X)-'\t'<5;}
#define isnum(X)   ((unsigned)(X)-'0' < 10)

int stod(const char *s){ //like atoi but no negatives and only for small numbers
   int r=0;
   while (ispad(*s++));
   while (isnum(*s)) r = 10*r + (*s++ - '0');
   return r;
}


static void dtos(int d, char *buf){ //like itoa, but you pass the buffer
   int p=0;
   if (0>d) {
      buf[p++]='-';
      d=-d;
   }
   if (0==d){
      buf[p++]='0';
      buf[p]=0;
      return;
   }
   int i=1000000000;
   while (i > d) i/=10;
   while (0<i){
      buf[p++]=('0'+(d/i));
      if (i<=d) d=d%i;
      i/=10;
   }
   buf[p]=0;
   return;
}



//GLOBALs

static char //default colors TODO read from config file
   *ln_c="#000", //lines, outlines, strokes, etc...
   *fg_c="#AAA", //foreground items ... usually the actual image
   *bg_c="#444", //background color ... todo match with theme
   *txt_c="#FFF", //use a text color that will work with both the bg and fg
   *chg_c="#0F0", //usually green indicates a preferred status
   *dchg_c="#F00", //usually red denotes less preferred status
   *width="22px", //set for standard tray size
   *height="22px";

static const char *HOME,
   hdr[]="<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" \tviewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" ",
   ftr[]="</svg>\n",
   w[]=" width=\"",
   h[]=" height=\"",
   x[]=" x=\"",
   y[]=" y=\"",
   q[]="\" ",
   tagend[]=">\n",
   tagclose[]="/>\n",
   rect[]="\t<rect ",
   fill[]=" fill=\"",
   txt[]="\t<text ",
   center[]=" text-anchor=\"middle\"",
   rotate[]=" transform=\"rotate(90 50,50)\"",
   fontsz[]=" font-size=\"",
   txtend[]="</text>\n";   

#if 0 //TODO
void do_wifi(){
const char upload[]="M71,29L99,2L99,27L92,18,75,34",
   download[] = "M98,0L70,27L70,5L77,12,90,0",
     updown[] = "<path d=\"%s\" fill=\"%s\" stroke=\"%s\"/>\n",
    sigqual[] = "<circle cx=\"0\" cy=\"100\" r=\"%d\" stroke=\"%s\" stroke-width=\"%d\" fill=\"%s\" fill-opacity=\"0.5\" />\n";

   static int lastrcv=0, lastxmt=0;
   int rcv,xmt,quality;

   FILE *wireless = fopen("/proc/net/wireless", "r");
   char dev[8], status[8], link[8], level[8], noise[8];
   fgets(dummy, 99, wireless);
   fgets(dummy, 99, wireless);
   while (fscanf(fp, "%s %s %s %s %s %s\n", ip, hw, flags, mac, mask, dev) != EOF)
      if (!strcmp(argv[1],ip))
         printf("%s\n",dev);
   return 0;
   
}
#endif

void do_bat(char *batt){
   const char BAT[]="/proc/acpi/battery/BAT";
   char buf[4096]={0}, *bp=(char *)buf, fname[32], dy[8], ht[8], ftsz[8],
      text[]="BAT0";
   static int dcap=0, rcap=-1, percent=-1;
   int i, fd, len=sizeof(buf), chg=0, cap=0;
   if (!isnum(*batt)) *batt='0';
   else text[3] = *batt;
   i=sizeof(fname);
   strcpyALL(fname, i, BAT, batt, "/info");
   if (( fd = open(fname,O_RDONLY))<0) return;
   len = read(fd,buf,len);
   close(fd);
   if (len < 0) return;
   buf[len]=0; //for strstr
   if (!dcap){ //only do once
      bp = strstr(buf,"design capacity:");
      if (!bp) return;
      dcap = stod(&bp[25]);
   }

   if ((bp = strstr(buf,"last ful"))) cap = stod(&bp[25]);
   else cap = dcap;
   i=sizeof(fname);
   strcpyALL(fname,i,BAT,(batt)?batt:"0","/state");
   if (( fd = open(fname,O_RDONLY))<0) return;
   i = read(fd,&(buf[len]),sizeof(buf)-len);
   close(fd);
   if (i < 0) return;
   else buf[(len+=i)]=0;

   if ((bp = strstr(buf,"remain")) && (i = stod(&bp[25])) == rcap) return;
   else rcap = i;
   if ((bp = strstr(buf,"charging st"))) chg=bp[25]-'c';
   i=sizeof(fname);
   strcpyALL(fname,i,HOME,"/.sit/b", batt, ".tt");
   if (( fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC))<0) return;
   len=write(fd,buf,len);
   close(fd);
   i=(rcap>cap)?(100*rcap)/cap:(100*rcap)/dcap;
   if (i==percent) return;
   else percent = i;
   i=sizeof(fname);
   strcpyALL(fname,i,HOME,"/.sit/b", batt, ".svg");
   if (( fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC))<0) return;
   dtos(100-percent,dy);
   dtos(percent,ht);
   dtos(100/(strlen(text)-1),ftsz);
   len=sizeof(buf);
   strcpyALL(buf, len, hdr, w, width, q, h, height, q, tagend,
      rect, x, "20%\"", w, "60%\"", h, "100%\"", fill, bg_c, q, tagclose,
      rect, x, "20%\"", w, "60%\"", y, dy, q, h, ht, q, fill, (chg)?dchg_c:chg_c, q, tagclose,
      //txt, x, "50\"", y, "50\"", fill, txt_c, q, fontsz, ftsz, q, center, rotate, tagend,   "\t\t", text, "\n", txtend,
      ftr
   );
   write(fd,buf,sizeof(buf)-len);
}

int main(int argc, char **argv){
   char buf[64];
   int len=sizeof(buf);
   HOME=getenv("HOME");
   strcpyALL(buf,len,HOME,"/.sit");
   mkdir(buf,0644);
   while(!sleep(1)){
      do_bat("0");
   }
   return 0;
}


_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Tue 09 Dec 2014, 12:43    Post subject:  

https://launchpad.net/sdesk

Here is the Launchpad page.

I licensed it Public Domain, because I finally found that licensing on the launchpad page.... I did that because you originally indicated that...
I also made an SVG version of your logo, so let me know if you want it.
I did that so I could scale it correctly for the Launchpad logos... it is very picky about sizes, and I needed to make sure it looked clean. Smile[/url]
Back to top
View user's profile Send private message 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Tue 09 Dec 2014, 21:51    Post subject:  

I am having trouble determining how to build that program using cmake...
I tried putting it in with the other program and building it with the previous flags, this however did not work.
I also tried removing -Os as this worked from geany once I removed that flag...
I am using pbuilder since I am debianizing this
here are the errors

Code:

make[3]: Entering directory `/tmp/buildd/sdesk-plugins-1.0.22/obj-x86_64-linux-gnu'
/usr/bin/cmake -E cmake_progress_report /tmp/buildd/sdesk-plugins-1.0.22/obj-x86_64-linux-gnu/CMakeFiles 1
[100%] Building C object CMakeFiles/proc2imgd.dir/plugins/proc2imgd.c.o
/usr/bin/gcc   -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security  -O3 -DNDEBUG   -o CMakeFiles/proc2imgd.dir/plugins/proc2imgd.c.o   -c /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c
/tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c: In function 'do_bat':
/tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:164:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
In file included from /usr/include/fcntl.h:252:0,
                 from /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:7:
In function 'open',
    inlined from 'do_bat.constprop.0' at /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:145:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
In function 'open',
    inlined from 'do_bat.constprop.0' at /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:153:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
In function 'open',
    inlined from 'do_bat' at /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:145:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
In function 'open',
    inlined from 'do_bat' at /tmp/buildd/sdesk-plugins-1.0.22/plugins/proc2imgd.c:153:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[3]: *** [CMakeFiles/proc2imgd.dir/plugins/proc2imgd.c.o] Error 1
make[3]: Leaving directory `/tmp/buildd/sdesk-plugins-1.0.22/obj-x86_64-linux-gnu'
make[2]: *** [CMakeFiles/proc2imgd.dir/all] Error 2
make[2]: Leaving directory `/tmp/buildd/sdesk-plugins-1.0.22/obj-x86_64-linux-gnu'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/tmp/buildd/sdesk-plugins-1.0.22/obj-x86_64-linux-gnu'
dh_auto_build: make -j1 returned exit code 2
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
E: Failed autobuilding of package

I am packaging it as sdesk plugins, where I will heap all the plugins together so they can be easily installed.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Tue 09 Dec 2014, 22:12    Post subject:  

torios wrote:
I did that so I could scale it correctly for the Launchpad logos... it is very picky about sizes, and I needed to make sure it looked clean. Smile
That's funny, Launchpad has got to be the most unclean interface ever developed ... almost as bizarre as Bazaar.

I had to drop plans for the application part of sdesk because the gtk devs won't add 10 lines of code for passing a simple string with gtkbuilder UIs. As it stands you have to have a C function for every single thing passed or do a bunch of hacks to add a special hidden label. Just another reason why gtk sucks

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Tue 09 Dec 2014, 22:24    Post subject:  

torios wrote:
I am having trouble determining how to build that program using cmake...
I tried putting it in with the other program and building it with the previous flags, this however did not work.
I also tried removing -Os as this worked from geany once I removed that flag...
I am using pbuilder since I am debianizing this
here are the errors
...
I am packaging it as sdesk plugins, where I will heap all the plugins together so they can be easily installed.

If you are talking about https://github.com/technosaurus/sdesk That was just an initial idea I was putting down from memory of the gtk API that I wrote using the touchscreen of my smartphone on the github web interface without ever doing an interim compiles. The tarball posted in this thread is the version that is based on the reality that redhat doesn't give a shit if gtk works for anything but their own cross platform applications. But please let me know if you or anyone else is successful in convincing them that the gtkbuilder UIs should be able to handle simple strings instead of every single thing needing to be an object. Not that it matters though as of the most recent gtk3 release, the gtkstatusicon (the core of SIT and the tray part of sdesk) is deprecated with no replacement.
What we need is an actual community fork of gtk2 so we can let gtk3 rot.

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Wed 10 Dec 2014, 23:03    Post subject:  

Haha... no..
I meant the proc2imgd file. I figured out how to build the sdesk program. I have packaged it and tested it... it is pretty sweet! I am making a man page for it, and I will test it out more. Though... there are some things that I will have to modify a little to work as a Debian package...

I also need to read up on 'alltray' and see how this works... I am quite interested in the possibilities of sdesk.

I used the code from this thread.... I just used the image from the github page
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Thu 11 Dec 2014, 09:32    Post subject:  

Here is the updated version: (compile with gcc -Os -o proc2imgd proc2imgd.c -s)
Code:
/*
 * proc2imgd.c
 *
 * Copyright 2014 Brad Conroy - released to public domain
 *
 */
#include <fcntl.h> //open
#include <unistd.h> //read,write
#include <string.h> //strstr, strlen
#include <stdlib.h> //getenv
#include <sys/stat.h> //mkdir
#include <sys/statfs.h> //for statfs
#include <stdint.h> //for *int*_t
#include <libgen.h> //basename

#define strcpyALL(buf, l, ...) do{ \
   char *bp=(char*)(buf); \
   const char *s, *a[] = { __VA_ARGS__,NULL}, **ss=a; \
   while((s=*ss++)) \
      while((*s)&&((--l) >0)) \
         *bp++=*s++; \
   *bp=0; \
}while(0)

static inline int ispad(int X){return (X)==' '||(unsigned)(X)-'\t'<5;}
#define isnum(X)   ((unsigned)(X)-'0' < 10)

int stod(const char *s){ //like atoi but no negatives and only for small numbers
   int r=0;
   while (ispad(*s))s++;
   while (isnum(*s)) r = 10*r + (*s++ - '0');
   return r;
}


static void dtos(int64_t d, char *buf){ //like itoa, but you pass the buffer
   int p=0;
   if (0>d) {
      buf[p++]='-';
      d=-d;
   }
   if (0==d){
      buf[p++]='0';
      buf[p]=0;
      return;
   }
   int64_t i=1000000000000000000;
   while (i > d) i/=10;
   while (0<i){
      buf[p++]=('0'+(d/i));
      if (i<=d) d=d%i;
      i/=10;
   }
   buf[p]=0;
   return;
}


//GLOBALs

static char //default colors TODO read from config file
   *ln_c="#000", //lines, outlines, strokes, etc...
   *fg_c="#AAA", //foreground items ... usually the actual image
   *bg_c="#444", //background color ... todo match with theme
   *txt_c="#FFF", //use a text color that will work with both the bg and fg
   *chg_c="#0F0", //usually green indicates a preferred status
   *dchg_c="#F00", //usually red denotes less preferred status
   *width="22px", //set for standard tray size
   *height="22px",
   buf[4096]={0},
   HOME[64];

static const char
   hdr[]="<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" \tviewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" ",
   ftr[]="</svg>\n",
   w[]=" width=\"",
   h[]=" height=\"",
   x[]=" x=\"",
   y[]=" y=\"",
   q[]="\" ",
   tagend[]=">\n",
   tagclose[]="/>\n",
   rect[]="\t<rect ",
   fill[]=" fill=\"",
   txt[]="\t<text ",
   center[]=" text-anchor=\"middle\"",
   rotate[]=" transform=\"rotate(90 50,50)\"",
   fontsz[]=" font-size=\"",
   txtend[]="</text>\n";   

#if 0
static inline void do_wifi(const char *wlan){
const char upload[]="M71,29L99,2L99,27L92,18,75,34",
   download[] = "M98,0L70,27L70,5L77,12,90,0",
     updown[] = "<path d=\"%s\" fill=\"%s\" stroke=\"%s\"/>\n",
    sigqual[] = "<circle cx=\"0\" cy=\"100\" r=\"%d\" stroke=\"%s\" stroke-width=\"%d\" fill=\"%s\" fill-opacity=\"0.5\" />\n";

   static int lastrcv=0, lastxmt=0;
   int rcv,xmt,quality;

   FILE *wireless = fopen("/proc/net/wireless", "r");
   char dev[8], status[8], link[8], level[8], noise[8];
   fgets(dummy, 99, wireless);
   fgets(dummy, 99, wireless);
   while (fscanf(fp, "%s %s %s %s %s %s\n", ip, hw, flags, mac, mask, dev) != EOF)
      if (!strcmp(argv[1],ip))
         printf("%s\n",dev);
   return 0;
   
}
#endif

static inline void do_fs(char *fname, int *lastsz){
   char extensions[]=" kMGTE", sz[8], *bp, outfile[64];
   size_t ext=0, len=sizeof(outfile);
   int fd;
   if (!fname) return;
   struct statfs st;
   if ((statfs(fname, &st))<0) return;
   uint64_t left = st.f_bfree * st.f_bsize;
   while(left>1024){
      left>>=10; //same as /=1024
      ++ext;
   }
   if ((int)left == *lastsz) return; //try not to trigger unnecessary redraw
   else *lastsz=left;
   dtos(left,sz);
   bp=sz+strlen(sz);
   if (ext) *bp++=extensions[ext];
   *bp++='b';*bp++='\n';*bp++=0;
   strcpyALL(outfile, len,HOME,(const char *)basename(fname),".svg");
   if (( fd = open(outfile,O_WRONLY|O_CREAT|O_TRUNC))<0) return;
   len=sizeof(buf);
   strcpyALL(buf, len,
      hdr, w, width, q, h, height, q, tagend,
         rect, w, "100%\"", h, "100%\"", fill, bg_c, q, tagclose,
         txt, x, "50\"", y, "50\"", fill, txt_c, q, fontsz, "30", q, center, tagend,   "\t\t",
            sz, "\n",
         txtend,
      ftr
   );   
   write(fd,buf,strlen(buf));
   close(fd);
   return;
}


static inline void do_bat(char *batt, int *percent){
   const char BAT[]="/proc/acpi/battery/";
   char *bp=(char *)buf, fname[32], dy[24], ht[24];
   int i, fd, len=sizeof(buf), chg=0, cap=-1, dcap=-1, rcap=-1;

/* We _could_ just do this block once, but last full capacity may change */
   i=sizeof(fname);
   strcpyALL(fname, i, BAT, batt, "/info");
   if (( fd = open(fname,O_RDONLY))<0) return;
   len = read(fd,buf,len);
   close(fd);
   if (len < 0) return;
   buf[len]=0; //for strstr
   if (!(bp = strstr(buf,"design capacity:"))) return;
   else dcap = stod(&bp[25]);
   if ((bp = strstr(buf,"last ful"))) cap = stod(&bp[25]);
   else cap = dcap;

   i=sizeof(fname);
   strcpyALL(fname,i,BAT,batt,"/state");
   if (( fd = open(fname,O_RDONLY))<0) return;
   i = read(fd,&(buf[len]),sizeof(buf)-len);
   close(fd);
   if (i < 0) return;
   else buf[(len+=i)]=0;

   if ((bp = strstr(buf,"remain")) && (i = stod(&bp[25])) == rcap) return;
   else rcap = i;
   if ((bp = strstr(buf,"charging st"))) chg=bp[25]-'c';
   i=sizeof(fname);
   i=(100*rcap)/((rcap>cap)?dcap:cap);
   if (*percent==((chg)?-i:i)) return; //try not to trigger unnecessary redraw
   else *percent = i;
   strcpyALL(fname,i,HOME, batt, ".tt");
   if (( fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC))<0) return;
   len=write(fd,buf,len);
   close(fd);
   i=sizeof(fname);
   strcpyALL(fname,i,HOME, batt, ".svg");
   if (( fd = open(fname,O_WRONLY|O_CREAT|O_TRUNC))<0) return;
   dtos(100-*percent,dy);
   dtos(*percent,ht);
   if (chg) *percent=-*percent;
   len=sizeof(buf);
   strcpyALL(buf, len, hdr, w, width, q, h, height, q, tagend,
      rect, x, "20%\"", w, "60%\"", h, "100%\"", fill, bg_c, q, tagclose,
      rect, x, "20%\"", w, "60%\"", y, dy, q, h, ht, q, fill, (chg)?dchg_c:chg_c, q, tagclose,
      txt, x, "50\"", y, "50\"", fill, txt_c, q, fontsz, "30", q, center, rotate, tagend,   "\t\t", batt, "\n", txtend,
      ftr
   );
   write(fd,buf,sizeof(buf)-len);
}

int main(int argc, char **argv){
   int len=sizeof(HOME),
      state[argc/2];
   strcpyALL(HOME,len,getenv("HOME"),"/.sit/");
   mkdir(HOME,0422);
   do{
      do_fs("/mnt/save",&state[0]);
      do_bat("BAT0",&state[1]);
      //do_wifi("wlan0",&state[2]); //todo
   }while(!sleep(1));
   return 0;
}


_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Sat 13 Dec 2014, 10:12    Post subject:  

Hi again,
I am still getting the same type of error.
I have never used GTK in my programs so I will have to look into it, I am a bit wary of it since GTK has been in a blender for the past few years. I usually write things using FLTK because it is very fast and light. And FLUID makes it very simple to make interfaces look the way you want them to.

Anyhow here is the error... it keeps looking for 3 args.
Code:

/usr/bin/gcc   -Os -o -O3 -DNDEBUG   -o CMakeFiles/proc2imgd.dir/plugins/proc2imgd.c.o   -c /tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c
/tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c: In function 'do_fs':
/tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:142:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
/tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c: In function 'do_bat':
/tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:198:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
In file included from /usr/include/fcntl.h:252:0,
                 from /tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:7:
In function 'open',
    inlined from 'do_fs.constprop.1' at /tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:132:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
In function 'open',
    inlined from 'do_bat.constprop.0' at /tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:182:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
In function 'open',
    inlined from 'do_bat.constprop.0' at /tmp/buildd/sdesk-plugins-1.0.23/plugins/proc2imgd.c:187:7:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments


I think pbuilder automatically adds in -O3 -DNDEBUG
as I have
Code:
set(CMAKE_C_FLAGS "-Os -o")

in my CMakeLists.txt
Thanks for helping me with this!

On a side note I made a nice locate dialog using gxmessage and zenity. It is very neat to have a search tool available right in my panel.
I am looking forward to adding more features soon (like this monitoring program you have made... if it will only compile in pbuilder)
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Sat 13 Dec 2014, 11:52    Post subject:  

Stop using cmake and just compile with the command posted at the top of my last post. if you are going to use cmake the "-o" is not a flag, it denotes the next argument is the name of the output binary.
To make a standalone binary, just:
gcc -Os -o proc2imgd proc2imgd.c -s

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Sun 14 Dec 2014, 09:56    Post subject:  

Hi, sorry I have been a bit under the weather.
-o is definitely not a C flag... please ignore that...
I want to use cmake because I want to package this for debian.

open can take 3 arguments, so I think I will just add the third argument (mode) and see what happens... that seems to be the main complaint from the compiler/pbuilder.

I don't know that cmake is as big of a problem here as the pbuilder building system... they use extremely strict rules to govern what code will work, and what code will not build. When I get some time I will test this out and let you know...

There may be something else I could do... what about using a flag to denote what standard of C is being used... I know there is such a thing in C++ i.e.
Quote:
-std=c++0x

I have had to use this in order to get certain programs to compile correctly for similar issues.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4764
Location: Kingwood, TX

PostPosted: Mon 15 Dec 2014, 06:58    Post subject:  

oops, the ones with O_CREAT should have a mode afterward.... just add ,0644

my static build with musl just uses defaults and it is smaller than the shared glibc build (mostly because I don't use any printf or scanf functions)

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
torios


Joined: 05 Dec 2014
Posts: 28

PostPosted: Mon 15 Dec 2014, 18:47    Post subject:  

Thanks technosaurus! I really appreciate this. Should I use this format:
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
to be in line with the previous argument?
Or is the numerical permission better?

I know this is kind of a minor stylistic question, but this is your code so I like to always ask people before I modify their code, especially since I have contact with you directly. I feel like this promotes the openness we appreciate about libre software.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 9 of 11 [160 Posts]   Goto page: Previous 1, 2, 3, ..., 7, 8, 9, 10, 11 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1629s ][ Queries: 12 (0.0194s) ][ GZIP on ]