[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Creating a non-focused window
- From: James Scott Jr <skoona verizon net>
- To: Tom Machinski <tom machinski gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Creating a non-focused window
- Date: Thu, 22 May 2008 22:38:14 -0400
Tom,
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.
James,
** required rpms: yum install libnotify libnotify-devel
BEGIN CODE:
/* notice.c
Compile Command:
$ gcc `pkg-config --cflags --libs libnotify` -o notice notice.c
Usage:
$ ./notice -s 5 -t "title of messagebox" -m "message in the box"
or
$ ./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", 't', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_title,
"Title text on msg box", "Title goes here!"},
{"message", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_body,
"Message body text", "message"},
{"icon-name", 'i', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
&gd_pch_icon,
"icon to include next to message",
"gtk-dialog-info ...-warning ...-error"},
{"show-seconds", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
&gd_i_seconds,
"seconds to display message", "10"},
{NULL}
};
/* 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);
g_option_context_free(context);
g_error_free(gerror);
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;
}
notify_init(argv[0]);
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;
}
g_object_unref(G_OBJECT(nctx));
notify_uninit();
return 0;
}
END CODE:
On Thu, 2008-05-22 at 17:26 -0700, Tom Machinski wrote:
> Hi,
>
> 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 window.show(). 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?
>
> Tom
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]