Re: A simple GtkSpinner is very costly in CPU cycles

2018-03-22 Thread Eric Cashon via gtk-app-devel-list

 

 
Hi Kian

For effeciency, use one of the default cursors.

https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html

If you want, you can try creating your own cursor with animation and using 
that. I got this working on my netbook which isn't a very high powered computer 
by todays standards and it works fine. I don't see it eating up cpu cycles. 
Give it a try and see if it works.

Eric


//gcc -Wall cursor1.c -o cursor1 `pkg-config gtk+-3.0 --cflags --libs`
//Tested on Ubuntu16.04, GTK3.18.

#include

static guint timeout_id=0;
static GdkCursor *cursors[4];

static void initialize_cursors(GtkWidget *window, GdkPixbuf *pixbufs[]);
static void start_cursor(GtkButton *button1, GtkWidget *da);
static void stop_cursor(GtkButton *button2, GtkWidget *da);
static gboolean update_cursor(GtkWidget *da);
static GdkPixbuf* draw_cursor(gint section);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Cursors");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

//Pixbufs for the different cursors.
GdkPixbuf *pixbuf1=draw_cursor(1);
GdkPixbuf *pixbuf2=draw_cursor(2);
GdkPixbuf *pixbuf3=draw_cursor(3);
GdkPixbuf *pixbuf4=draw_cursor(4);
GdkPixbuf *pixbufs[]={pixbuf1, pixbuf2, pixbuf3, pixbuf4};
g_signal_connect(window, "realize", G_CALLBACK(initialize_cursors), 
pixbufs);

GtkWidget *button1=gtk_button_new_with_label("Start Cursor");
gtk_widget_set_hexpand(button1, TRUE);

GtkWidget *button2=gtk_button_new_with_label("Stop Cursor");
gtk_widget_set_hexpand(button2, TRUE);

//Display the cursor in a drawing area.
GtkWidget *da=gtk_drawing_area_new();
gtk_widget_set_hexpand(da, TRUE);
gtk_widget_set_vexpand(da, TRUE);

g_signal_connect(button1, "clicked", G_CALLBACK(start_cursor), da);
g_signal_connect(button2, "clicked", G_CALLBACK(stop_cursor), da);
  
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 1, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), da, 0, 1, 2, 1);
  
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);

gtk_main();

g_object_unref(pixbuf1); 
g_object_unref(pixbuf2); 
g_object_unref(pixbuf3); 
g_object_unref(pixbuf4); 
g_object_unref(cursors[0]);
g_object_unref(cursors[1]);
g_object_unref(cursors[2]);
g_object_unref(cursors[3]);

return 0;
  }
static void initialize_cursors(GtkWidget *window, GdkPixbuf *pixbufs[])
  {
GdkWindow *win=gtk_widget_get_window(window);
GdkDisplay *display=gdk_window_get_display(win);
GdkCursor *cursor1=gdk_cursor_new_from_pixbuf(display, pixbufs[0], 1, 32);
GdkCursor *cursor2=gdk_cursor_new_from_pixbuf(display, pixbufs[1], 1, 32);
GdkCursor *cursor3=gdk_cursor_new_from_pixbuf(display, pixbufs[2], 1, 32);
GdkCursor *cursor4=gdk_cursor_new_from_pixbuf(display, pixbufs[3], 1, 32);
cursors[0]=cursor1;
cursors[1]=cursor2;
cursors[2]=cursor3;
cursors[3]=cursor4;
  }
static void start_cursor(GtkButton *button1, GtkWidget *da)
  {
if(timeout_id==0)
  {
timeout_id=g_timeout_add(300, (GSourceFunc)update_cursor, da);
  }
  }
static void stop_cursor(GtkButton *button2, GtkWidget *da)
  {
if(timeout_id!=0)
  {
g_source_remove(timeout_id);
timeout_id=0;
GdkWindow *win=gtk_widget_get_window(da);
gdk_window_set_cursor(win, NULL);
  }
  }
static gboolean update_cursor(GtkWidget *da)
  {
static gint i=0;

GdkWindow *win=gtk_widget_get_window(da);
gdk_window_set_cursor(win, cursors[i]);
if(i>2) i=0;
else i++;
 
return TRUE;
  }
static GdkPixbuf* draw_cursor(gint section)
  { 
//Create a surface to draw on. 
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 
64, 64);
cairo_t *cr=cairo_create(surface);

//Paint the background transparent.
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.0);
cairo_paint(cr);

cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
cairo_rectangle(cr, 0.0, 0.0, 64.0, 64.0);
cairo_stroke(cr);

//Draw from center
cairo_translate(cr, 64.0/2.0, 64.0/2.0);

cairo_set_source_rgba(cr, 0.0, 1.0, 1.0, 1.0);
cairo_arc(cr, 0.0, 0.0, 20.0, 0.0, 2.0*G_PI);
cairo_fill(cr);

//Some pie wedges.
if(section==1)
  {
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_move_to(cr, 0.0, 0.0);
cairo_line_to(cr, 20.0, 0.0);
cairo_stroke_preserve(cr);
cairo_arc(cr, 0.0, 0.0, 20.0, 0.0, G_PI/2.0);
cairo_stroke_preserve(cr);
cairo_close_path(cr);
cairo_fill(cr);
  }
else if(section==2)
  {
cairo_set_source_rgb(cr, 

Re: compiling glade

2018-03-22 Thread Tristan Van Berkom
On Thu, 2018-03-22 at 19:13 +0100, arkkimede wrote:
> Thank You Tristan for Your Kindness.
> Unfortunately, this new release of Glade require libgtk-3.20.0 and in
> my linuxbox Ubuntu 16.04 I have only 3.18.0.
> The 3.20.0 is present in Ubuntu 17 but this release is not stable
> enough to start to work with it.
> 
> Thank you in any case. 

Ok, in that case, I recommend the following:

Follow instructions to install BuildStream, better to follow the wiki
page here:

https://wiki.gnome.org/Newcomers/BuildSystemComponent

Or directly:

http://buildstream.gitlab.io/buildstream/install.html
(pay attention to the system requirements, the debian
instructions should be close to ubuntu)

Then once you have installed BuildStream, do the following:

# Get the build metadata repo
#
$ git clone https://gitlab.gnome.org/GNOME/gnome-build-meta.git

# Build Glade
#
$ bst build --track-all world/glade.bst

# Run Glade, note the --mount option just makes your /home available
# in the shell, so you can edit files in your home dir.
#
$ bst shell --mount /home /home world/glade.bst

... this will drop you into a shell, where you can run `glade` ...

This will take a bunch of your disk space, and may take a long time the
first time around, because we dont have a regular builder contributing
to the shared artifact cache *yet*.

However, so long as BuildStream can be installed on Ubuntu 16.04, it
should get you glade from git master reliably.

Cheers,
-Tristan

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: compiling glade

2018-03-22 Thread Tristan Van Berkom
Hi,

On Thu, 2018-03-22 at 14:52 +0100, arkkimede wrote:
> HI!
> I want to install the latest version of glade downloaded from git-hub.
> 
> I read the instruction.
> 
> There is written that configure.ac or configure.in is used to generate the
> script configure.
> To do that execute the command autoconf.
> 
> I executed this command but some macro are missed
> 
> Searching I found who write:
> to solve the problem run "autoreconf -fvi".
> 
> Running this command it ends with this error:
> 
> automake: error: cannot open < gtk-doc.make: No such file or directory
> autoreconf: automake failed with exit status: 1
> 
> consider that I've installed
> 
> libgtk-3-doc
> gtk-doc-tools.
> 
> Please, could you help me?

First just noting, this question would be better targeted at the Glade
users mailing list: glade-us...@lists.ximian.com

But I'll just answer you here anyway :)

I suggest you use the most recent tarball release, which is very
recent; at:

  https://download.gnome.org/sources/glade/3.22/glade-3.22.0.tar.xz

Otherwise, to build directly from the official upstream git repository,
which can be found at: https://git.gnome.org/browse/glade (if there is
a github, it is either only a mirror, or it is someone's private fork),
you should use the autogen.sh script, feeding it directly the arguments
you would normally pass to ./configure

When building directly from git, you have a couple of extra
requirements, so it is a little bit harder than just using the release
tarball - you will need at least gtkdocize, and I think libtoolize,
along with the m4-common macros.

Note that once you have *built* Glade, you need to install it, you can
install it to any prefix you like, it need not be installed to /usr,
but it will not run directly from the build directory.

Cheers,
-Tristan

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

compiling glade

2018-03-22 Thread arkkimede
HI!
I want to install the latest version of glade downloaded from git-hub.

I read the instruction.

There is written that configure.ac or configure.in is used to generate the
script configure.
To do that execute the command autoconf.

I executed this command but some macro are missed

Searching I found who write:
to solve the problem run "autoreconf -fvi".

Running this command it ends with this error:

automake: error: cannot open < gtk-doc.make: No such file or directory
autoreconf: automake failed with exit status: 1

consider that I've installed

libgtk-3-doc
gtk-doc-tools.

Please, could you help me?
Thamks
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: A simple GtkSpinner is very costly in CPU cycles

2018-03-22 Thread Kian Karas
On Wed, Mar 21, 2018 at 10:17 AM, Emmanuele Bassi  wrote:

> On 20 March 2018 at 14:06, Kian Karas  wrote:
>
>> Hi smart people
>>
>> I just introduced animation, in the form of a GtkSpinner, to my
>> application
>> for the first time. When the spinner is animating, the application takes
>> up
>> 45 % of the CPU resources (the application is otherwise idle at 0-2,6 %).
>> The CPU is a single core ARM Cortex-A7 running at 528 MHz (maximum).
>>
>> This seems like a lot of MIPS for rotating an image of approximately 20x20
>> px.
>>
>>
> The rotation is performed through CSS, in order to be stylable by themes;
> this means that the CSS state has to be invalidated in order to recompute
> the next frame, and this is there the cost lies.
>
> Of course, 45% is a pretty big chunk of a core, so it's indeed problematic
> on single core, low performance devices. It's going to be the case for
> every animation involving CSS, though, so you may elect to either disable
> animations on your platform, or use a static placeholder image. There's
> also the option of using a theme that does not have as many states for the
> spinner animation, thus causing fewer invalidations.
>
> I'm new to GTK (and CSS). Thus, I don't know the option you mention in
above last sentence. Do you know of a source where I can learn about doing
that? I mean, is there are tutorial touching on the spinner animation?

It's for an embedded system, so I do not need support for different themes.
Thus, unless I can figure out how to do above, I'll just make my own
progress indication using slower update of a GtkImage (cycling through
different images).

We are actively working to fix the issue on GTK 4, but changing the CSS
> subsystem has the potential of breaking GTK 3 applications, so it's not on
> the roadmap, outside of low impact optimizations.
>
> Ciao,
>  Emmanuele.
>
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list