Re: Cannot send a notifications onto a gnome desktop environment, what do I wrong.

2016-12-07 Thread Ben Iofel
For GNotification to work, you need a .desktop file installed with the same
name as your application-id

Otherwise you can use libnotify directly without a .desktop file

On Tue, Dec 6, 2016, 2:01 PM eddie  wrote:

> Hi everybody,
>
> I have write the following code but their is no way to send a
>
> notification even
>
> if it's say that isn't guarantee that something will happen in the
> documentation
>
> concerning notifications with gtk/gio.
>
> ```C
>
> #include 
> #include 
> #include 
>
> #define DEBUG_FUNC_MARK  do { fprintf(stdout,"\n%s(...) called\n",
> __func__) ; } while(0) ;
>
> /** GtkApplication example:
>*
>* To compile with:
>*
>* $ cc gtk_GtkApplication.c `pkg-config --cflags --libs gtk+-3.0`
>*
> */
> static void activate (GApplication *application, gpointer user_data) ;
>
> static void startup(GApplication *application, gpointer user_data) ;
>
> static void open_files(GApplication  *application, GFile **files, gint
> n_files, const gchar *hint) ;
>
>
>
> static void about_activated(GSimpleAction *action, GVariant *parameter,
> gpointer app) ;
>
> static void preferences_activated(GSimpleAction *action, GVariant
> *parameter, gpointer app) ;
>
> static void quit_activated(GSimpleAction *action, GVariant *parameter,
> gpointer   app) ;
>
> static void shutdown_app(GApplication *application, gpointer user_data) ;
>
>
>
> void destroy(GtkWidget *widget, gpointer pointer) ;
>
> static gboolean delete_event(GtkWidget *widget,GdkEvent *event,gpointer
> pointer) ;
>
> GtkApplication *app;
>
> int main (int argc, char **argv) {
>
>int status;
>
>GtkWidget *window ;
>
>
>// Given the program a name to displaying to the user through:
> g_get_application_name().
>g_set_application_name("myapp") ;
>
>const char *app_id = "myapp.org" ;
>
>if ( ! g_application_id_is_valid(app_id) ) {
>
>  fprintf(stderr, "Wrong app id\n") ;
>  exit(EXIT_FAILURE) ;
>
>}
>
>
>// Setting the applications flags
>int app_flags = G_APPLICATION_HANDLES_OPEN ;
>
>app_flags |=  G_APPLICATION_NON_UNIQUE ;
>app_flags |=  G_APPLICATION_SEND_ENVIRONMENT ;
>
>
>app = gtk_application_new(app_id, (GApplicationFlags) app_flags) ;
>
>// The ::activate signal is emitted on the primary instance when an
> activation occurs. When g_application_activate() is called.
>g_signal_connect( G_APPLICATION(app),  "activate",
> G_CALLBACK(activate),   NULL) ;
>// The ::open signal is emitted on the primary instance when there
> are files to open.
>g_signal_connect( G_APPLICATION(app),  "open",
> G_CALLBACK(open_files), NULL) ;
>// The ::startup signal is emitted on the primary instance
> immediately after registration. When g_application_register() is called.
>g_signal_connect( G_APPLICATION(app),  "startup",
> G_CALLBACK(startup),NULL) ;
>// The ::shutdown signal is emitted only on the registered primary
> instance immediately after the main loop terminates.
>g_signal_connect( G_APPLICATION(app),  "shutdown",
> G_CALLBACK(shutdown_app),NULL) ;
>
>GError *err = NULL ;
>
>g_application_register(G_APPLICATION(app), NULL, ) ;
>
>if (err != NULL) {
>
>  fprintf(stderr,"Cannot register app: %s\n", err->message) ;
>  exit(EXIT_FAILURE) ;
>
>}
>
>
>
>fprintf(stdout,"GtkApplication DBUS path: %s\n",
> g_application_get_dbus_object_path(G_APPLICATION(app)) ) ;
>
>GtkBuilder *builder;
>GMenuModel *app_menu ;
>
>static GActionEntry app_entries[] = {
>
>  { "preferences",  preferences_activated,  NULL, NULL, NULL },
>  { "about",about_activated,NULL, NULL, NULL },
>  { "quit", quit_activated, NULL, NULL, NULL }
>
>};
>
>g_action_map_add_action_entries(G_ACTION_MAP(app), app_entries,
> G_N_ELEMENTS(app_entries), app);
>
>builder = gtk_builder_new_from_file("./GtkApplication/menus.ui");
>
>fprintf(stdout,"builder: %p\n", builder) ;
>
>app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
>
>if (gtk_application_prefers_app_menu(app)) {
>
>  gtk_application_set_app_menu(GTK_APPLICATION(app), app_menu);
>
>}
>
>g_object_unref (builder);
>
>
>//g_application_set_inactivity_timeout( G_APPLICATION(app), 1) ;
>
>
>window = gtk_application_window_new(app)  ;
>
> g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(destroy),NULL) ;
>
>
> g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(delete_event),NULL)
> ;
>
>gtk_widget_show_all(window) ;
>
>
>
>
>g_application_set_default(g_application_get_default()) ;
>
>g_application_activate(G_APPLICATION(app)) ;
>
>status = g_application_run(G_APPLICATION(app), argc, argv) ;
>
>g_object_unref (app);
>
>return status;
> }
>
> static void activate(GApplication *application, gpointer user_data) {
>
>#ifdef DEBUG
>DEBUG_FUNC_MARK
>

Re: listening to stdin in the controlling terminal after gtk_main is called

2016-09-14 Thread Ben Iofel
create a GIOChannel with g_io_channel_unix_new()

and
then add it to the main context with *g_io_add_watch()
*

On Thu, Sep 15, 2016 at 12:52 AM Dan Hitt  wrote:

> HI All,
>
> I'm writing a gtk application and i would like it to listen to stdin
> in the controlling terminal after gtk_main() is called.
>
> So for example, when you type a carriage return in the controlling
> terminal, all the characters which have been typed since the last
> carriage return are gathered up into a string, and the app receives
> some event containing the string, and it has some handler that can
> interpret and deal with it.
>
> This would be analogous to listening for key presses in a window,
> except that they don't come from a window, and instead of arriving a
> character at a time they'd arrive a string at a time.
>
> Now, i imagine it cannot be quite that simple, because that doesn't
> sound like any of the events listed in gdkevents.h.
>
> But on the other hand something along these lines must be possible
> since applications like mpv certainly do listen to their stdin and
> respond to it (as well as listening to characters that are typed to
> their windows).
>
> And there should be a select() or something to make it possible for an
> apparatus such as gtk to do this.
>
> And i don't even know how to google around for a solution :(
>
> So i'd appreciate any hints on how to do this.
>
> (And although it would be awesome to be able to read a character at a
> time from stdin, a line at a time would certainly do, and i'd probably
> have to plan on line-at-a-time anyway for the case when the app was
> launched from a emacs buffer.)
>
> TIA!
>
> dan
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Adding and removing widgets at runtime

2016-09-12 Thread Ben Iofel
Why not just make async network requests on the UI thread?

On Mon, Sep 12, 2016 at 12:37 PM Daniel.  wrote:

> Well, if I wasn't clear before my layout is totally questionable. I
> more generic question would be:
>
> How you guys aproaches when the problem is showing applications
> behavior on screen?
>
> My backend logic is something like this:
>
> - Start a new thread for each address passed in command line. Address
> are 32bits numbers.
> - At each thraed:
>   - While (true)
>  - Make the background yellow
>  - Send a message and wait for response (a blocking call)
>  - If timeout set background red
>  - else set background green
>  - showup the latency (how much time the "Send a message" taken)
>  - wait a second so that user can see other background color than
> yellow
>
> - Start a new thread to receive events
>   - While (true)
> - when some event arrive:
>- instantiate a new label describing the event and show it onto
> the screen
>- reply the event (blocks till reply acknowledge)
>- remove the event from the screen
>
>
> Is there any monitoring software that reacts to outside world events
> and show then in some GTK GUI? That would be a good inspiration :)
>
> Best regards,
>
> 2016-09-12 13:19 GMT-03:00 Daniel. :
> > Hi thank you guys for the replies,
> >
> > Gergely, I can't really use FlowBox since I'm depending on gtk2, not
> > 3. So the solution is really implementing my own widget as Joël said
> > .. Joël in swing I usually use an event queue so that there is only
> > one thread doing GUI modifications. Is that pattern used often in gtk?
> > I think that this pattern is cleaner and more ellegant that
> > synchronizing at every single thread, the problem is that I can't have
> > lambda expressions in C :(. How would I apply this pattern to GTK?
> >
> > Best regards,
> >
> > 2016-09-12 12:56 GMT-03:00 Joël Krähemann :
> >> Hi again
> >>
> >> Don't mess synchronized with a mutex. The closest thing to
> >> synchronized would be ags_task_thread_append_task()
> >> and run things exclusively
> >>
> >>
> http://git.savannah.gnu.org/cgit/gsequencer.git/tree/ags/thread/ags_task_thread.h?h=0.7.x
> >>
> >> bests,
> >> Joël
> >>
> >>
> >>
> >> On Mon, Sep 12, 2016 at 5:50 PM, Joël Krähemann 
> wrote:
> >>> Hi
> >>>
> >>> Since I know Javax/Swing I can tell you there is no synchronize
> >>> keyword doing your magic.
> >>>
> >>> Please take a look at pthread_mutex_lock(), pthread_cond_wait(),
> >>> pthread_cond_signal(), pthread_cond_broadcast()
> >>> or pthread_barrier_wait().
> >>>
> >>> Bests,
> >>> Joël
> >>>
> >>>
> >>> On Mon, Sep 12, 2016 at 5:17 PM, Joël Krähemann 
> wrote:
>  Hi
> 
>  You can't do that without implementing your own widget because of
>  thread-safety issues. To do your own
>  GtkFlowBox implement GtkWidget:size-allocate and
>  GtkWidget:size-request the rest is up to you.
> 
>  Don't forget doing mutices or use g_timeout_add() but this is single
>  threaded and is invoked by
>  g_main_context_iteration().
> 
>  For a simple example consider this:
> 
> 
> http://git.savannah.gnu.org/cgit/gsequencer.git/tree/ags/X/editor/ags_notebook.c?h=0.7.x#n167
> 
>  It is a scrolled window containing buttons doing a scrollable area.
> 
>  You have to use gdk_threads_enter() and gdk_threads_leave(). Might be
>  you have even to acquire
>  the GMainContext.
> 
>  Bests,
>  Joël
> 
> 
> 
>  On Mon, Sep 12, 2016 at 5:03 PM, Gergely Polonkai <
> gerg...@polonkai.eu> wrote:
> > Hello,
> >
> > I have no knowledge of Java/Swing, but based on your requirements I
> guess
> > you need FlowBox[1].
> >
> > Best,
> > Gergely
> >
> > [1] https://developer.gnome.org/gtk3/stable/GtkFlowBox.html
> >
> > On Mon, Sep 12, 2016, 16:35 Daniel.  wrote:
> >
> >> Hi everybody,
> >>
> >> I have a library implementing some protocol. That library is
> >> multithread and is responsible to delivery messages to remote nodes
> >> and retrieve it's responses. I need to visualise the whole mess
> >> running.
> >>
> >> To do this I wrote a simple application in Java/Swing where for each
> >> remote node one thread is created. The thread will send a message
> and
> >> wait for response in a closed loop. Each thread is represented at
> GUI
> >> by a label on the screen. When it's idle the background of that
> label
> >> becomes green, when is waiting for response it is yellow and if
> >> timeouts it becomes red. All labels have the same information so
> that
> >> they have exactly the same size.
> >>
> >> Beside the request/repsonse there is events that can arrive from the
> >> nodes too. That events need to be replied as 

Re: How to get objecttype

2016-09-10 Thread Ben Iofel
in C, you can use the GTK_IS_COMO_BOX and GTK_IS_ENTRY macros on GtkWidget*


On Fri, Sep 9, 2016 at 9:14 AM Thomas Rønshof  wrote:

> Hi,
>
> We are converting some OLD COBOL applications to GTK.
> The XML is created dynamically from SCREEN SECTIONS and we then use
> gtk_builder to get the objects into the program.
>
> Is there a way to get the objecttype ?
> If it's a gtk-combo we do this, if it's a gtk-entry we do that in the
> program and so on...
>
> Can gtk_builder_get_type_from_name() be used ?
>
> Regards
>
> Thomas
>
>
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: disabling mouse scroll on GtkComboBox and spin buttons

2016-05-22 Thread Ben Iofel
There's a utility function for just returning true: gtk_true

On Sun, May 22, 2016, 6:53 AM  wrote:

> On 22 May 2016 at 10:57, Florian Pelz  wrote:
> > On 05/22/2016 11:54 AM, jcup...@gmail.com wrote:
> >> x = gtk_combo_box_new_text();
> >> g_signal_connect(x, "scroll-event", G_CALLBACK(true_cb), NULL);
> >> ...
> >
> > Ah yes, this is a much better way.
>
> I'm not sure it'd work for spin buttons though :-(
>
> Something like your event masks, Florian, would probably be necessary for
> that.
>
> John
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: libvte color troubles.

2015-09-21 Thread Ben Iofel
> GdkColor Color = { 0, 22323, 0xff * 255, 0xff * 255 };
That doesn't look right. Shouldn't colors be in 0..255?

On Mon, Sep 21, 2015, 8:12 AM Subsentient  wrote:

> Writing a new terminal application with GTK and libvte, and setting
> colors is not working.
>
> I'd like to know what I'm doing wrong.
>
> vte_terminal_set_color_background() is ignored. Nothing changes, no
> warnings appear in stdout or stderr, just, nothing.
>
>
> Here's some stub code that illustrates my problem.
>
> P.S. It's curiously hard to find a decent guide on libvte. And yes, I
> know vte_terminal_fork_command() is deprecated.
>
> #include 
> #include 
> int main(int argc, char **argv)
> {
>  gtk_init(, );
>
>
>  GtkWidget *Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>
>  GtkWidget *Term = vte_terminal_new();
>  GdkColor Color = { 0, 22323, 0xff * 255, 0xff * 255 };
>  vte_terminal_set_color_background((VteTerminal*)Term, );
>
>  vte_terminal_set_size((VteTerminal*)Term, 50, 30);
>
>
>
>
>  const char *ShellArgv[] = { "/usr/bin/bash", NULL };
>
>  gtk_container_add((GtkContainer*)Win, Term);
>
>  vte_terminal_fork_command((VteTerminal*)Term,
> (char*)*ShellArgv, (char**)ShellArgv, NULL, NULL, TRUE, TRUE, TRUE );
>
>
>  gtk_widget_show_all(Win);
>
>  gtk_main();
>
>  return 0;
> }
>
>
>
>
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Proper use of g_main_context_iteration

2015-08-11 Thread Ben Iofel
Why not make it single threaded with
https://developer.gnome.org/glib/unstable/glib-The-Main-Event-Loop.html#g-main-context-add-poll

On Tue, Aug 11, 2015 at 8:27 PM Jacques Pelletier jpellet...@ieee.org
wrote:

 Hi,

 I'm using a separate thread for accepting clients on a socket server.
 In this thread, the g_main_context_iteration is called to update the GUI.

 Do I need to use g_main_context_acquire and/or g_main_context_release?

 Apart from the code and the reference manuals, there's not much infos
 about the proper use of these functions.
 What are these for? Where can I get a more detailled description of
 these functions?

 Thanks!

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

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