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 Wed 17 Sep 2014, 05:33
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Fun with C
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 3 [39 Posts]   Goto page: Previous 1, 2, 3 Next
Author Message
01micko


Joined: 11 Oct 2008
Posts: 7801
Location: qld

PostPosted: Mon 21 Jul 2014, 07:16    Post subject:  

technosaurus wrote:
What, no xcb + cairo-xcb port?


Rome wasn't built in a day Razz

technosaurus wrote:
j/k I know how difficult it is to find good xcb examples


This one looks useful as a start.

technosaurus wrote:
- though I did find enough to write a very basic xcbmessage program a while back (no fancy cairo based images though)


I remember that! I had a bit of a look at xcb but went xlib because it fell into place ( = more docs and examples, which I referenced in the github readme). The program does what I want and looks ok, contrary to vovchik's "so goddamn ugly" comment. Of course the glam is all cairo.

Q> in your opinion, briefly, what are the advantages of xcb over xlib?

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Mon 21 Jul 2014, 08:38    Post subject:  

01micko wrote:
Q> in your opinion, briefly, what are the advantages of xcb over xlib?
xlib is ... xlib. xcb is smaller, faster and asynchronous You could have one thread sending requests, one handling responses, another handling errors and another (or a few) handling their callbacks while other threads handle program stuff. With xlib you send a request, wait for a response, handle, repeat. With glibc threads are actually pretty heavy (8MB+ or so each), but musl-libc has really lightweight threads (in the 10s of kb range). Now that quad-core processors with multiple execution units are a virtual standard even in mobile space, xcb _could_ really make a difference especially with openMP and other technologies that make it easier for us to take advantage. A few of us have been using musl pretty extensively and the rough edges are getting much smoother but we haven't really tested the threads much.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7801
Location: qld

PostPosted: Mon 21 Jul 2014, 08:50    Post subject:  

Interesting.

For my little venture, a very simple splash, xlib seems to suffice.

But..
technosaurus wrote:
xcb is smaller, faster and asynchronous You could have one thread sending requests, one handling responses, another handling errors and another (or a few) handling their callbacks while other threads handle program stuff.


Remember when you had ideas to make icons for a JWM only desktop? What about xcb and cairo for that? Sure, a bit of a project. I don't think musl would support the cairo part though, not without extensive (probably way too much work) patching.

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Mon 21 Jul 2014, 14:32    Post subject:  

see goingnuts' patches to idesk, they turned out pretty well.
It would be a shame to use an external program though, jwm already has everything in place to create them... I have even simulated icons using a solid color background and matching no-border trays for each icon (vertically oriented, fixed position with a icon+tooltip on top and optionally text on bottom) We only need a way to set individual tray background colors (probably as a property) and have the color be none (copy from parent)...not opacity as it is, that affects everything on the tray as well. If that happens I'll update my jwm tools to a 1.0 version.

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
matiasbatero


Joined: 11 Oct 2012
Posts: 60
Location: Mar del Plata, Argentina

PostPosted: Tue 22 Jul 2014, 13:32    Post subject:  

I'm new in programming. I'm started with C a week ago.

The code, compiles and runs OK.
But it is only a functional structure.

structs, pointers, unions etc.. in order to provide a:
"Readable post-code".
str.c.tar
Description 
tar

 Download 
Filename  str.c.tar 
Filesize  5 KB 
Downloaded  41 Time(s) 
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2155
Location: The Blue Marble

PostPosted: Fri 25 Jul 2014, 10:04    Post subject:  

My entry: Xannotate, a desktop annotation tool.

EDIT: add screenshot.

EDIT: Version 2014-07-27 now supports three pens, eraser, and support for alpha transparency (faster!) if you run a compositing manager (xcompmgr, compton, or kwin). Still works even if you don't have them.

Draw with left-button, erase with right-button. Shift-left-click changes pens. 'Pause' to enter/leave drawing mode, Shift-Pause to show/hide drawing, Ctrl-Pause to clear drawing and start over, Alt-Shift-Pause to capture a screenshot (in PNG format, with or without your drawing in it). Ctrl-Shift-Pause to exit.

And you can change "Pause" to something else.

Depends only on Xlib (libX11, libXext, libXrender) and pnglite which is included.
xannotate00000.png
 Description   The annotation was done directly on screen, not in mtpaint
 Filesize   43.07 KB
 Viewed   376 Time(s)

xannotate00000.png


_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 2326
Location: Heart of Texas

PostPosted: Sat 26 Jul 2014, 21:17    Post subject:  

JB how are you capturing keypresses would same be used for onscreen keyboard under fatdog64 and ARM? Very Happy
I keep bringing this up because it has halted the project at a year now. I am having the yearly visit with the Dr. next week. She moved on and had most of our ideas done in window tablets since then. I posted a link to the news story ( That should have been a show with Fatdog !!) Wink
Back to top
View user's profile Send private message 
8-bit


Joined: 03 Apr 2007
Posts: 3368
Location: Oregon

PostPosted: Sun 27 Jul 2014, 01:33    Post subject:  

In writing something in C, sometimes one gets carried away in writing the code and fails to add sufficient comment sections to the code to explain what a section of the code is supposed to do.
And later, without comments in the code, one may go back to code he/she has written and be at a loss as to trying to make sense of it.
So with any C code, I recommend heavy commenting.
It only increases the source code file size and and does not increase the size of the compiled result.
Also, it helps others in understanding what the code does.

And keep in mind that C programmers may not have the level of experience you have. So cryptic comments will not help.
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2247

PostPosted: Sun 27 Jul 2014, 06:56    Post subject:  

I think programmers should spend their first five years only learning to write good comments... LOL
Back to top
View user's profile Send private message 
Ted Dog


Joined: 13 Sep 2005
Posts: 2326
Location: Heart of Texas

PostPosted: Sun 27 Jul 2014, 08:34    Post subject:  

8-bit wrote:
In writing something in C, sometimes one gets carried away in writing the code and fails to add sufficient comment sections to the code to explain what a section of the code is supposed to do.
And later, without comments in the code, one may go back to code he/she has written and be at a loss as to trying to make sense of it.
So with any C code, I recommend heavy commenting.
It only increases the source code file size and and does not increase the size of the compiled result.
Also, it helps others in understanding what the code does.

And keep in mind that C programmers may not have the level of experience you have. So cryptic comments will not help.


I disagree. heavily commented code should be avoided to much cludder. Take a look at BKs scripts. Impossible to follow due to curtains of comments. On the other hand look and Kirks and JBs just enough at the key points of flow to speed understanding.
I followed a winner of the C http://www0.us.ioccc.org/
http://blog.aerojockey.com/post/iocccsim

in a job and ahhhhhh the horror. I took a c test that used the winners of that contest to get a job. I SO RAILED AGAINST that as a testing criteria I even correctly pointed out Carl had gave the interview the idea to use this as a C skill test, AND I WOULD NEVER SUBJECT ANYONE TO SUCH A NIGHTMARE, I do not justify my job security to code obfuscation. Got the job offer but refused ( second time working after Carl I learned my lession )
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2155
Location: The Blue Marble

PostPosted: Sun 27 Jul 2014, 15:43    Post subject:  

Ted Dog wrote:
JB how are you capturing keypresses would same be used for onscreen keyboard under fatdog64 and ARM? Very Happy
I keep bringing this up because it has halted the project at a year now. I am having the yearly visit with the Dr. next week. She moved on and had most of our ideas done in window tablets since then. I posted a link to the news story ( That should have been a show with Fatdog !!) Wink

xvkbd should have worked. I remember I tested it and it did. I'm not too confident of matchbox_keyboard. Anyway, the way I capture the keyboard is XGrabKey - every X-based "hotkey" manager would do it that way, nothing special.

I have another entry for this: Xscreenshot, a simple program to take screenshot of selected area of the desktop. Its specialty: you can use it to quickly take successive screenshots. Especially useful when taking screenshot for documentation. Saves to PNG file. Depends only on Xlib.

xannotate is 22K, xscreenshot is 17K. This is on x86_64; I'm sure it is smaller on x86.

Enjoy.

From the readme:
README wrote:
xscreenshot is a simple program to take screenshot of your desktop.

You can run it to take a single screenshot, or run it in multiple-shots mode.

The single-shot mode is meant to be used with other hotkey programs
(such as xbindkeys). In this mode, once you have taken your screenshot
it will exit. This is the default mode.

In multiple-shots mode, xscreenshot will run until you tell it to exit.
You can toggle between normal mode, or screenshot taking mode.
In normal mode, the mouse can be used as normal (hence the name).
In screenshot mode, you can take multiple screenshots, one after another.

The screenshot is saved as PNG file.

Mouse buttons
-------------
Left-click: press to start selection, move to choose, release to take a shot.
Right-click:
- if pressed during active selection (that is, when left-button is pressed too):
cancel selection, and you can start over.
- if pressed when there is no active selection:
- in single-shot mode, xscreenshot will exit
- in multiple-shot mode: no effect

Keys usage
----------
Hotkey - toggle screenshot/normal mode
Ctrl-Shift-hotkey - terminate xscreenshot

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7801
Location: qld

PostPosted: Tue 29 Jul 2014, 06:35    Post subject:  

More xlib/cairo fun ... I really should learn xcb next as xlib can suck Surprised

pmck

Compiled on 64 it's 20k stripped. Slightly less on x86.

readme wrote:
pmck
====

a poor man's clock

This is a simple analog clock based on xlib and cairo.

This is not meant for production systems as it has bugs and was written just as
a proof of concept.

Build
-----
Just run 'make' and install the pmck the binary in your path. Optionally,
install the pmckrc file to $HOME/.config/ and edit to your preferences.

Usage
-----
Just run 'pmck' from the command line, it needs no options. It will read an rc file
in $HOME/.config/pmckrc to set different features. There is an example rc file
provided. This should be self explanatory. You can set the size, background
and foreground colours and the style, 2 to choose from. You can autostart it if
you wish. See your distro's documentation for this feature.

On some window managers the root window is not the desktop window. In the case
of ROX-Filer pinboard this is easily overcome by finding the child window which
is "ROX-Pinboard", which in most cases is the very first child. However, in the
case of XFCE I had trouble coding the correct window so added 1 single option to the
command line; the desktop window ID which can be found by running "xwininfo" and
clicking on a blank part of the desktop. The string will be a hex value something
like "0xae44010". Just type (or script) "pmck $hex_value_here". This should work
with any other WM/DE also as it overrides the internal algorithm.

Bugs
----
- must quit with CTRL-C or kill, there is code block supposed to quit with 'q'.. Sad
- redraws forever, so may use too much CPU and eventually memory
- may run 1 or 2 seconds behind system time.
- need a click on desktop to display (rox bug - FIXED)
- some window managers may need the the window on top for the clock to display
- can flicker at times of heavy load or on slow machines
- a compositor such as xcompmgr is needed so artefacts do not display under clockface
- at larger sizes the second hand may flicker or disappear


Free virtual beer/coffee/other beverage for the one who solves the quit bug!

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 29 Jul 2014, 08:05    Post subject:  

maybe try

Code:
   while (1) {
      XNextEvent(dpy, &e);
      if(e.type == Expose && e.xexpose.count < 1) {
         //while (1) {
            paint(cs, width, height, style);
         //   usleep(500000);
         //}

      }
      else if (e.type == KeyPress) {
         char buf[128] = {0};
         KeySym keysym;
         XLookupString(&e.xkey, buf, sizeof buf, &keysym, NULL);
         if (keysym == XK_q) {
            break;
         }
      }
      usleep(500000); //moved here for cpu usage
   }

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7801
Location: qld

PostPosted: Tue 29 Jul 2014, 08:12    Post subject:  

Nope. Clock doesn't redraw and it doesn't quit. Sorry, no chocolates.
_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
jamesbond

Joined: 26 Feb 2007
Posts: 2155
Location: The Blue Marble

PostPosted: Tue 29 Jul 2014, 13:16    Post subject:  

Make sure you prepare plenty of beers and chocolates Laughing Better make it real not virtual Laughing Laughing

change
Code:
XSelectInput(dpy, win, ExposureMask|KeyPressMask);

to
Code:
XSelectInput(dpy, win, ExposureMask|KeyPressMask|ButtonPressMask);

then change your loop to this one.
Code:

   while (1) {
      while (XPending (dpy))
      {
         XNextEvent(dpy, &e);
         if (e.type == KeyPress) {
            char buf[128] = {0};
            KeySym keysym;
            XLookupString(&e.xkey, buf, sizeof(buf), &keysym, NULL);
            if (keysym == XK_q) {
               goto finish;
            }
         } else if (e.type == ButtonPress) {
            XSetInputFocus (dpy, win, RevertToNone, CurrentTime);
         }
      }
      paint(cs, width, height, style);
      usleep(500000);
   }
finish:
   cairo_surface_destroy(cs);
   XCloseDisplay(dpy);


To quit, click the clock, then press q.

Quote:
On some window managers the root window is not the desktop window. In the case
of ROX-Filer pinboard this is easily overcome by finding the child window which
is "ROX-Pinboard", which in most cases is the very first child.

Doesn't work for me. I only run openbox + rox; and I have to resort to using xwininfo trick.
Quote:
- a compositor such as xcompmgr is needed so artefacts do not display under clockface
Not enough. Do this: run pmck; cover it with something, show it again (and see the garbage), *then* run xcompmgr. xcompmgr will not remove that garbage (in fact it will keep it). Learn to use XShapeCombineMask instead, and you will not depend on xcompmgr at all.
_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 3 [39 Posts]   Goto page: Previous 1, 2, 3 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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.1126s ][ Queries: 13 (0.0037s) ][ GZIP on ]