Re: Creating a non-focused window


This might be a opportunity to explore and use 'libnotify' and have a
libnotify-popup present your message.

As for your original question, I don't have an answer that I treid and
know for certain will work.  However, This is what I would try by
changing my code; 1. I would reread the gtk api to understand if
gtk_widget_show() vs gtk_widget_show_all() vs gdk_window_present() would
make the messagebox/window visible without redirecting focus.
Otherwise, I would disable-focus, show the window, re-enable focus. 

On the other hand, libnotify should like the best way to proceed.  Here
is a quick sampler.


** required rpms: yum install libnotify libnotify-devel

/* notice.c  
  Compile Command:
   $ gcc `pkg-config --cflags --libs libnotify` -o notice notice.c
   $ ./notice -s 5 -t "title of messagebox" -m "message in the box"
   $ ./notice --help


#include <libnotify/notify.h>

/* cmd line var pointers */
static gchar   *gd_pch_title;
static gchar   *gd_pch_body;
static gchar   *gd_pch_icon;
static gint     gd_i_seconds;

int main(int argc, char * argv[] ) 
    NotifyNotification *nctx;  
    GError  *gerror = NULL;
    GOptionContext *context = NULL; /* --help message for command line
    GOptionEntry entries[] = {
         "Title text on msg box", "Title goes here!"},
      {"message", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
         "Message body text", "message"},
      {"icon-name", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
         "icon to include next to message",
"gtk-dialog-info ...-warning ...-error"},
      {"show-seconds", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
         "seconds to display message", "10"},         
    /* Get command line parms */    
    context = g_option_context_new (
                " - Commandline Notification Utility"
                " GPL2 [2008] <Skoona users sourceforge net>");
    g_option_context_add_main_entries(context, entries, NULL);

    g_option_context_set_ignore_unknown_options(context, FALSE); 

    g_option_context_set_help_enabled (context, TRUE);

    if (!(g_option_context_parse(context, &argc, &argv, &gerror))) {
         g_warning ("Parse command line failed: %s", gerror->message);
         return (1);

    if (gd_pch_title == NULL) {
        gd_pch_title = "Title really needs to be here.";
    if (gd_pch_body == NULL) {
        gd_pch_body = "message goes here.";
    if (gd_pch_icon == NULL) {
        gd_pch_icon = "gtk-dialog-info";
    if (gd_i_seconds < 1 ) {
        gd_i_seconds = 10;

    nctx = notify_notification_new (gd_pch_title, gd_pch_body,
gd_pch_icon, NULL); 
    notify_notification_set_timeout (nctx, (gd_i_seconds * 1000) ); //
10 seconds

    if (!notify_notification_show (nctx, NULL)) 
    g_warning ("failed to send notification");
    return 2;


    return 0;


On Thu, 2008-05-22 at 17:26 -0700, Tom Machinski wrote:

I wrote a simple GTK+ application that displays a popup window.

The problem is that whenever the window is displayed, it immediately gets
("steals") the focus. I would like to prevent that from happening: i.e., the
window should be created and displayed, but it should not be focused, but
instead focus should be retained by whatever window had it before the
creation of the new window.

The only way I know to do that is by calling window.set_accept_focus(False)
before The serious flaw with that method is that the
resulting window, while being prevented from stealing the focus, also can
not receive focus at any later time, even by intentional user action.

Any better approaches?

gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]