Little cleanup
parent
3b8ec37af2
commit
6713b65477
31
configure.ac
31
configure.ac
|
@ -41,35 +41,8 @@ AC_PROG_INSTALL
|
|||
MOO_AC_PROG_WINDRES
|
||||
|
||||
|
||||
# for pcre
|
||||
AC_CHECK_FUNCS(memmove bcopy strerror)
|
||||
|
||||
#for GMappedFile
|
||||
AC_CHECK_HEADERS(unistd.h)
|
||||
AC_CHECK_FUNCS(mmap)
|
||||
|
||||
#for moofileutils.c
|
||||
AC_CHECK_FUNCS(unlink)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Terminal stuff
|
||||
#
|
||||
AC_CHECK_HEADERS(poll.h errno.h io.h fcntl.h sys/types.h sys/wait.h signal.h)
|
||||
AC_CHECK_FUNCS([poll pipe _pipe kill signal posix_openpt])
|
||||
AC_TYPE_SIGNAL
|
||||
AC_TYPE_SIZE_T
|
||||
AC_TYPE_PID_T
|
||||
|
||||
# Check for headers.
|
||||
AC_CHECK_HEADERS(sys/select.h sys/termios.h sys/un.h stropts.h termios.h wchar.h)
|
||||
AC_HEADER_TIOCGWINSZ
|
||||
|
||||
# Check for PTY handling functions.
|
||||
AC_CHECK_FUNCS(cfmakeraw getpgid getpt grantpt unlockpt ptsname ptsname_r recvmsg)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Misc stuff
|
||||
MOO_AC_FUNCS
|
||||
|
||||
# Check debug options
|
||||
# TODO TODO check gcc
|
||||
|
|
|
@ -268,16 +268,16 @@
|
|||
</kdevdoctreeview>
|
||||
<kdevfilecreate>
|
||||
<filetypes>
|
||||
<type icon="source" ext="g" name="GAP source" create="template" >
|
||||
<type icon="source" ext="g" create="template" name="GAP source" >
|
||||
<descr>A new empty GAP source file</descr>
|
||||
</type>
|
||||
<type icon="source_cpp" ext="cpp" name="C++ Source" create="template" >
|
||||
<type icon="source_cpp" ext="cpp" create="template" name="C++ Source" >
|
||||
<descr>A new empty C++ file.</descr>
|
||||
</type>
|
||||
<type icon="source_h" ext="h" name="C/C++ Header" create="template" >
|
||||
<type icon="source_h" ext="h" create="template" name="C/C++ Header" >
|
||||
<descr>A new empty header file for C/C++.</descr>
|
||||
</type>
|
||||
<type icon="source_c" ext="c" name="C Source" create="template" >
|
||||
<type icon="source_c" ext="c" create="template" name="C Source" >
|
||||
<descr>A new empty C file.</descr>
|
||||
</type>
|
||||
</filetypes>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <mooutils/moocombo.h>
|
||||
#include <mooutils/moodialogs.h>
|
||||
#include <mooutils/mooentry.h>
|
||||
#include <mooutils/moofileutils.h>
|
||||
#include <mooutils/mooutils-misc.h>
|
||||
#include <mooutils/moofilewatch.h>
|
||||
#include <mooutils/moofiltermgr.h>
|
||||
#include <mooutils/mooglade.h>
|
||||
|
@ -44,7 +44,6 @@
|
|||
#include <mooutils/mootoggleaction.h>
|
||||
#include <mooutils/moouixml.h>
|
||||
#include <mooutils/mooutils-gobject.h>
|
||||
#include <mooutils/moowin.h>
|
||||
#include <mooutils/moowindow.h>
|
||||
#include <mooutils/moofileview/moobookmarkmgr.h>
|
||||
#include <mooutils/moofileview/moofile.h>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/moowin.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
|
||||
|
||||
#ifdef VERSION
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "mooedit/mooplugin.h"
|
||||
#include "mooutils/mooprefsdialog.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "mooapp/moopythonconsole.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moowin.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooentry.h"
|
||||
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooutils/moomarshals.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mooedit/mooeditfileops.h"
|
||||
#include "mooedit/mooeditdialogs.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moofilewatch.h"
|
||||
#include <string.h>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "mooutils/moomenuaction.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moomarshals.h"
|
||||
#include "mooutils/moowin.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include "mooutils/moofilewatch.h"
|
||||
#include <string.h>
|
||||
|
|
|
@ -597,25 +597,6 @@
|
|||
|
||||
;; From ../mooutils/moofileutils.h
|
||||
|
||||
(define-function moo_save_file_utf8
|
||||
(c-name "moo_save_file_utf8")
|
||||
(return-type "gboolean")
|
||||
(parameters
|
||||
'("const-char*" "name")
|
||||
'("const-char*" "text")
|
||||
'("gssize" "len")
|
||||
'("GError**" "error")
|
||||
)
|
||||
)
|
||||
|
||||
(define-function moo_unlink
|
||||
(c-name "moo_unlink")
|
||||
(return-type "int")
|
||||
(parameters
|
||||
'("const-char*" "filename")
|
||||
)
|
||||
)
|
||||
|
||||
(define-function moo_open_url
|
||||
(c-name "moo_open_url")
|
||||
(return-type "gboolean")
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "mooterm/mooterm-prefs.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ utilsinclude_headers = \
|
|||
mooglade.h \
|
||||
moohistoryentry.h \
|
||||
moohistorylist.h \
|
||||
moolog.h \
|
||||
moomarkup.h \
|
||||
moomenumgr.h \
|
||||
moonotebook.h \
|
||||
|
@ -56,13 +55,13 @@ utilsinclude_headers = \
|
|||
mooprefsdialogpage.h \
|
||||
moostock.h \
|
||||
mooutils-gobject.h \
|
||||
moowin.h \
|
||||
mooaccel.h \
|
||||
mooaction.h \
|
||||
mooactiongroup.h \
|
||||
moomenuaction.h \
|
||||
mootoggleaction.h \
|
||||
moouixml.h \
|
||||
mooutils-misc.h \
|
||||
moowindow.h \
|
||||
mooutils-python.h
|
||||
|
||||
|
@ -89,15 +88,12 @@ libmooutils_la_SOURCES = \
|
|||
moodialogs.c \
|
||||
moodialogs.h \
|
||||
mooentry.c \
|
||||
moofileutils.c \
|
||||
moofileutils.h \
|
||||
moofilewatch.c \
|
||||
moofilewatch.h \
|
||||
moofiltermgr.c \
|
||||
mooglade.c \
|
||||
moohistoryentry.c \
|
||||
moohistorylist.c \
|
||||
moolog.c \
|
||||
moomarkup.c \
|
||||
moomenumgr.c \
|
||||
moonotebook.c \
|
||||
|
@ -107,7 +103,7 @@ libmooutils_la_SOURCES = \
|
|||
mooprefsdialogpage.c \
|
||||
moostock.c \
|
||||
mooutils-gobject.c \
|
||||
moowin.c \
|
||||
mooutils-misc.c \
|
||||
mooaccel.c \
|
||||
mooaccelprefs-glade.h \
|
||||
mooaction.c \
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
#include "mooutils/moowin.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
|
||||
|
||||
static void message_dialog (GtkWidget *parent,
|
||||
|
|
|
@ -1,291 +0,0 @@
|
|||
/*
|
||||
* mooutils/moofileutils.c
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
/* XXX remove all this junk */
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_ERRNO_H
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <gdk/gdk.h>
|
||||
#include <string.h>
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
# include <gdk/gdkx.h>
|
||||
#endif
|
||||
#include "mooutils/moofileutils.h"
|
||||
#ifdef __WIN32__
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <shellapi.h>
|
||||
#endif
|
||||
#if GLIB_CHECK_VERSION(2,6,0)
|
||||
# include <glib/gstdio.h>
|
||||
#endif
|
||||
|
||||
/* TODO TODO move this to moocompat.h and copy from glib */
|
||||
int moo_unlink (const char *filename)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION(2,6,0)
|
||||
return g_unlink (filename);
|
||||
#elif HAVE_UNLINK
|
||||
return unlink (filename);
|
||||
#else
|
||||
#error "unlink() is absent"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* TODO TODO remove this thing */
|
||||
gboolean moo_save_file_utf8 (const char *name,
|
||||
const char *text,
|
||||
gssize len,
|
||||
GError **error)
|
||||
{
|
||||
GError *err = NULL;
|
||||
GIOChannel *file;
|
||||
gsize bytes_written;
|
||||
gsize real_len;
|
||||
|
||||
file = g_io_channel_new_file (name, "w", &err);
|
||||
if (!file) {
|
||||
g_assert (err != NULL);
|
||||
if (error) *error = err;
|
||||
else g_error_free (err);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
real_len = len < 0 ? strlen (text) : (gsize)len;
|
||||
g_io_channel_write_chars (file, text,
|
||||
len, &bytes_written,
|
||||
&err);
|
||||
|
||||
if (bytes_written != real_len || err != NULL) {
|
||||
if (err) {
|
||||
if (error) *error = err;
|
||||
else g_error_free (err);
|
||||
}
|
||||
g_io_channel_shutdown (file, TRUE, NULL);
|
||||
g_io_channel_unref (file);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_io_channel_shutdown (file, TRUE, NULL);
|
||||
g_io_channel_unref (file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
static gboolean open_uri (const char *uri, gboolean email/* = FALSE */)
|
||||
{
|
||||
g_return_val_if_fail (uri != NULL, FALSE);
|
||||
HINSTANCE h = ShellExecute (NULL, "open", uri, NULL, NULL,
|
||||
SW_SHOWNORMAL);
|
||||
return (int)h > 32;
|
||||
}
|
||||
|
||||
#else /* ! __WIN32__ */
|
||||
|
||||
|
||||
typedef enum {
|
||||
KDE,
|
||||
GNOME,
|
||||
DEBIAN,
|
||||
UNKNOWN
|
||||
} Desktop;
|
||||
|
||||
|
||||
static gboolean open_uri (const char *uri,
|
||||
gboolean email /* = FALSE */)
|
||||
{
|
||||
gboolean result = FALSE;
|
||||
char **argv = NULL;
|
||||
|
||||
Desktop desktop = UNKNOWN;
|
||||
char *kfmclient = g_find_program_in_path ("kfmclient");
|
||||
char *gnome_open = g_find_program_in_path ("gnome-open");
|
||||
char *x_www_browser = g_find_program_in_path ("x-www-browser");
|
||||
|
||||
if (!email &&
|
||||
g_file_test ("/etc/debian_version", G_FILE_TEST_EXISTS) &&
|
||||
x_www_browser)
|
||||
desktop = DEBIAN;
|
||||
|
||||
if (desktop == UNKNOWN) {
|
||||
if (kfmclient && g_getenv ("KDE_FULL_SESSION")) desktop = KDE;
|
||||
else if (gnome_open && g_getenv ("GNOME_DESKTOP_SESSION_ID")) desktop = GNOME;
|
||||
}
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
if (desktop == UNKNOWN) {
|
||||
const char *wm =
|
||||
gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ());
|
||||
if (wm) {
|
||||
if (!g_ascii_strcasecmp (wm, "kwin") && kfmclient)
|
||||
desktop = KDE;
|
||||
else if (!g_ascii_strcasecmp (wm, "metacity") && gnome_open)
|
||||
desktop = GNOME;
|
||||
}
|
||||
}
|
||||
#endif /* GDK_WINDOWING_X11 */
|
||||
|
||||
if (desktop == UNKNOWN) {
|
||||
if (!email && x_www_browser) desktop = DEBIAN;
|
||||
else if (kfmclient) desktop = KDE;
|
||||
else if (gnome_open) desktop = GNOME;
|
||||
}
|
||||
|
||||
switch (desktop) {
|
||||
case KDE:
|
||||
argv = g_new0 (char*, 4);
|
||||
argv[0] = g_strdup (kfmclient);
|
||||
argv[1] = g_strdup ("exec");
|
||||
argv[2] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case GNOME:
|
||||
argv = g_new0 (char*, 3);
|
||||
argv[0] = g_strdup (gnome_open);
|
||||
argv[1] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case DEBIAN:
|
||||
argv = g_new0 (char*, 3);
|
||||
argv[0] = g_strdup (x_www_browser);
|
||||
argv[1] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case UNKNOWN:
|
||||
if (uri)
|
||||
g_warning ("could not find a way to open uri '%s'", uri);
|
||||
else
|
||||
g_warning ("could not find a way to open uri");
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
if (argv) {
|
||||
GError *err = NULL;
|
||||
result = g_spawn_async (NULL, argv, NULL, (GSpawnFlags)0, NULL, NULL,
|
||||
NULL, &err);
|
||||
if (err) {
|
||||
g_warning ("%s: error in g_spawn_async", G_STRLOC);
|
||||
g_warning ("%s: %s", G_STRLOC, err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
}
|
||||
|
||||
if (argv) g_strfreev (argv);
|
||||
g_free (gnome_open);
|
||||
g_free (kfmclient);
|
||||
g_free (x_www_browser);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* ! __WIN32__ */
|
||||
|
||||
|
||||
gboolean moo_open_email (const char *address,
|
||||
const char *subject,
|
||||
const char *body)
|
||||
{
|
||||
GString *uri;
|
||||
gboolean res;
|
||||
|
||||
g_return_val_if_fail (address != NULL, FALSE);
|
||||
uri = g_string_new ("mailto:");
|
||||
g_string_append_printf (uri, "%s%s", address,
|
||||
subject || body ? "?" : "");
|
||||
if (subject)
|
||||
g_string_append_printf (uri, "subject=%s%s", subject,
|
||||
body ? "&" : "");
|
||||
if (body)
|
||||
g_string_append_printf (uri, "body=%s", body);
|
||||
|
||||
res = open_uri (uri->str, TRUE);
|
||||
g_string_free (uri, TRUE);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
gboolean moo_open_url (const char *url)
|
||||
{
|
||||
return open_uri (url, FALSE);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
int moo_gtimeval_compare (GTimeVal *val1,
|
||||
GTimeVal *val2)
|
||||
{
|
||||
g_return_val_if_fail (val1 != NULL && val2 != NULL, 0);
|
||||
|
||||
if (val1->tv_sec > val2->tv_sec)
|
||||
return 1;
|
||||
else if (val1->tv_sec < val2->tv_sec)
|
||||
return -1;
|
||||
else if (val1->tv_usec > val2->tv_usec)
|
||||
return 1;
|
||||
else if (val1->tv_usec < val2->tv_usec)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
GTime moo_get_file_mtime (const char *filename)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, MOO_EINVAL);
|
||||
|
||||
if (stat (filename, &buf)) {
|
||||
int err = errno;
|
||||
g_warning ("%s: error in stat()", G_STRLOC);
|
||||
g_warning ("%s: %s", G_STRLOC, g_strerror (err));
|
||||
switch (err) {
|
||||
case ENOENT:
|
||||
case ENOTDIR:
|
||||
case ENAMETOOLONG:
|
||||
#ifdef ELOOP
|
||||
case ELOOP:
|
||||
#endif
|
||||
return MOO_ENOENT;
|
||||
|
||||
case EACCES:
|
||||
return MOO_EACCESS;
|
||||
|
||||
case EIO:
|
||||
#ifdef ELOOP
|
||||
case EOVERFLOW:
|
||||
#endif
|
||||
return MOO_EIO;
|
||||
}
|
||||
}
|
||||
|
||||
return buf.st_mtime;
|
||||
}
|
||||
#endif
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* mooutils/moofileutils.h
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef MOOUTILS_FILEUTILS_H
|
||||
#define MOOUTILS_FILEUTILS_H
|
||||
|
||||
#include <glib/gerror.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#if 0
|
||||
/* TODO */
|
||||
/* st_mtime can't be negative, so error indicator is
|
||||
moo_get_file_mtime(file) < 0 */
|
||||
|
||||
#define MOO_EINVAL ((GTime) -1)
|
||||
#define MOO_EACCESS ((GTime) -2)
|
||||
#define MOO_EIO ((GTime) -3)
|
||||
#define MOO_ENOENT ((GTime) -4)
|
||||
|
||||
GTime moo_get_file_mtime (const char *filename);
|
||||
#endif
|
||||
|
||||
|
||||
gboolean moo_save_file_utf8 (const char *name,
|
||||
const char *text,
|
||||
gssize len,
|
||||
GError **error);
|
||||
int moo_unlink (const char *filename);
|
||||
|
||||
gboolean moo_open_url (const char *url);
|
||||
gboolean moo_open_email (const char *address,
|
||||
const char *subject,
|
||||
const char *body);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOOUTILS_FILEUTILS_H */
|
|
@ -20,259 +20,3 @@
|
|||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
typedef struct _MooLogWindow MooLogWindow;
|
||||
struct _MooLogWindow {
|
||||
GtkWidget *window;
|
||||
GtkTextTag *message_tag;
|
||||
GtkTextTag *warning_tag;
|
||||
GtkTextTag *critical_tag;
|
||||
GtkTextBuffer *buf;
|
||||
GtkTextView *textview;
|
||||
GtkTextMark *insert;
|
||||
};
|
||||
|
||||
|
||||
MooLogWindow *moo_log_window (void);
|
||||
GtkWidget *moo_log_window_get_widget (void);
|
||||
|
||||
|
||||
static MooLogWindow *moo_log_window_new (void)
|
||||
{
|
||||
MooLogWindow *log;
|
||||
GtkWidget *vbox, *scrolledwindow;
|
||||
PangoFontDescription *font;
|
||||
|
||||
log = g_new (MooLogWindow, 1);
|
||||
|
||||
log->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (log->window), "Log Window");
|
||||
gtk_window_set_default_size (GTK_WINDOW (log->window), 400, 300);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
gtk_widget_show (vbox);
|
||||
gtk_container_add (GTK_CONTAINER (log->window), vbox);
|
||||
|
||||
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolledwindow);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
|
||||
GTK_WIDGET_UNSET_FLAGS (scrolledwindow, GTK_CAN_FOCUS);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
|
||||
log->textview = GTK_TEXT_VIEW (gtk_text_view_new ());
|
||||
gtk_widget_show (GTK_WIDGET (log->textview));
|
||||
gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET (log->textview));
|
||||
GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (log->textview), GTK_CAN_FOCUS);
|
||||
gtk_text_view_set_editable (log->textview, FALSE);
|
||||
gtk_text_view_set_wrap_mode (log->textview, GTK_WRAP_WORD);
|
||||
|
||||
g_signal_connect (log->window, "delete-event",
|
||||
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
log->buf = gtk_text_view_get_buffer (log->textview);
|
||||
log->insert = gtk_text_buffer_get_insert (log->buf);
|
||||
log->message_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "message", "foreground", "blue", NULL);
|
||||
log->warning_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "warning", "foreground", "red", NULL);
|
||||
log->critical_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "critical", "foreground", "red",
|
||||
"weight", PANGO_WEIGHT_BOLD, NULL);
|
||||
|
||||
font = pango_font_description_from_string ("Courier New 9");
|
||||
if (font) {
|
||||
gtk_widget_modify_font (GTK_WIDGET (log->textview), font);
|
||||
pango_font_description_free (font);
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
void moo_log_window_write (const gchar *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const gchar *message)
|
||||
{
|
||||
char *text;
|
||||
GtkTextTag *tag = NULL;
|
||||
GtkTextIter end;
|
||||
MooLogWindow *log = moo_log_window ();
|
||||
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION)) {
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
if (log_domain)
|
||||
text = g_strdup_printf ("%s: %s\n", log_domain, message);
|
||||
else
|
||||
text = g_strdup_printf ("%s\n", message);
|
||||
|
||||
if (flags >= G_LOG_LEVEL_MESSAGE)
|
||||
tag = log->message_tag;
|
||||
else if (flags >= G_LOG_LEVEL_WARNING)
|
||||
tag = log->warning_tag;
|
||||
else
|
||||
tag = log->critical_tag;
|
||||
|
||||
gtk_text_buffer_get_end_iter (log->buf, &end);
|
||||
gtk_text_buffer_insert_with_tags (log->buf, &end, text, -1, tag, NULL);
|
||||
gtk_text_view_scroll_mark_onscreen (log->textview, log->insert);
|
||||
}
|
||||
|
||||
|
||||
MooLogWindow *moo_log_window (void)
|
||||
{
|
||||
static MooLogWindow *log = NULL;
|
||||
if (!log) log = moo_log_window_new ();
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
GtkWidget *moo_log_window_get_widget (void)
|
||||
{
|
||||
MooLogWindow *log = moo_log_window ();
|
||||
return log->window;
|
||||
}
|
||||
|
||||
|
||||
void moo_log_window_show (void)
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (moo_log_window()->window));
|
||||
}
|
||||
|
||||
void moo_log_window_hide (void)
|
||||
{
|
||||
gtk_widget_hide (moo_log_window()->window);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#define PLEASE_REPORT \
|
||||
"Please report it to emuntyan@sourceforge.net and provide "\
|
||||
"steps needed to reproduce this error."
|
||||
|
||||
#ifdef __WIN32__
|
||||
void moo_show_fatal_error (const char *logdomain, const char *logmsg)
|
||||
{
|
||||
char *msg = NULL;
|
||||
if (logdomain)
|
||||
msg = g_strdup_printf ("Fatal GGAP error:\n---\n%s: %s\n---\n"
|
||||
PLEASE_REPORT, logdomain, logmsg);
|
||||
else
|
||||
msg = g_strdup_printf ("Fatal GGAP error:\n---\n%s\n---\n"
|
||||
PLEASE_REPORT, logmsg);
|
||||
MessageBox (NULL, msg, "Error", MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
|
||||
g_free (msg);
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
static void log_func_file (const gchar *log_domain,
|
||||
G_GNUC_UNUSED GLogLevelFlags flags,
|
||||
const gchar *message,
|
||||
gpointer filename)
|
||||
{
|
||||
static gboolean firsttime = TRUE;
|
||||
static char *name = NULL;
|
||||
FILE *logfile;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION)) {
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
if (firsttime) {
|
||||
name = g_strdup ((char*)filename);
|
||||
logfile = fopen (name, "w+");
|
||||
firsttime = FALSE;
|
||||
}
|
||||
else
|
||||
logfile = fopen (name, "a+");
|
||||
|
||||
if (logfile) {
|
||||
if (log_domain)
|
||||
fprintf (logfile, "%s: %s\r\n", log_domain, message);
|
||||
else
|
||||
fprintf (logfile, "%s\r\n", message);
|
||||
fclose (logfile);
|
||||
}
|
||||
else {
|
||||
/* TODO ??? */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void log_func_silent (G_GNUC_UNUSED const gchar *log_domain,
|
||||
G_GNUC_UNUSED GLogLevelFlags flags,
|
||||
G_GNUC_UNUSED const gchar *message,
|
||||
G_GNUC_UNUSED gpointer data_unused)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION)) {
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
|
||||
|
||||
typedef void (*LogFunc) (const gchar *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const gchar *message,
|
||||
gpointer data);
|
||||
|
||||
|
||||
static void set_handler (LogFunc func, gpointer data)
|
||||
{
|
||||
#if !GLIB_CHECK_VERSION(2,6,0)
|
||||
g_log_set_handler ("Glib",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler ("Gtk",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler ("Pango",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler (NULL,
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
#else /* GLIB_CHECK_VERSION(2,6,0) */
|
||||
g_log_set_default_handler (func, data);
|
||||
#endif /* GLIB_CHECK_VERSION(2,6,0) */
|
||||
}
|
||||
|
||||
|
||||
void moo_set_log_func_window (int show)
|
||||
{
|
||||
if (show) moo_log_window_show ();
|
||||
set_handler ((LogFunc)moo_log_window_write, NULL);
|
||||
}
|
||||
|
||||
void moo_set_log_func_file (const char *log_file)
|
||||
{
|
||||
g_return_if_fail (log_file != NULL);
|
||||
set_handler (log_func_file, (char*)log_file);
|
||||
}
|
||||
|
||||
void moo_set_log_func (int show_log)
|
||||
{
|
||||
if (!show_log)
|
||||
set_handler (log_func_silent, NULL);
|
||||
else {
|
||||
#ifdef __WIN32__
|
||||
moo_set_log_func_window (FALSE);
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,21 +19,6 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
void moo_log_window_show (void);
|
||||
void moo_log_window_hide (void);
|
||||
|
||||
void moo_log_window_write (const gchar *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const gchar *message);
|
||||
|
||||
|
||||
void moo_set_log_func_window (int show);
|
||||
void moo_set_log_func_file (const char *log_file);
|
||||
void moo_set_log_func (int show_log);
|
||||
#ifdef __WIN32__
|
||||
void moo_show_fatal_error (const char *logdomain,
|
||||
const char *logmsg);
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "mooutils/moomarkup.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "mooutils/eggregex.h"
|
||||
#include "mooutils/moomarshals.h"
|
||||
#include "mooutils/moomarkup.h"
|
||||
#include "mooutils/moofileutils.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -0,0 +1,922 @@
|
|||
/*
|
||||
* mooutils-misc.c
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <shellapi.h>
|
||||
#endif
|
||||
#if GLIB_CHECK_VERSION(2,6,0)
|
||||
# include <glib/gstdio.h>
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
moo_unlink (const char *filename)
|
||||
{
|
||||
g_return_val_if_fail (filename != NULL, -1);
|
||||
|
||||
#if GLIB_CHECK_VERSION(2,6,0)
|
||||
return g_unlink (filename);
|
||||
#else
|
||||
return unlink (filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* XXX fix this */
|
||||
gboolean
|
||||
moo_save_file_utf8 (const char *name,
|
||||
const char *text,
|
||||
gssize len,
|
||||
GError **error)
|
||||
{
|
||||
GIOChannel *file;
|
||||
GIOStatus status;
|
||||
gsize bytes_written;
|
||||
gsize real_len;
|
||||
|
||||
file = g_io_channel_new_file (name, "w", error);
|
||||
|
||||
if (!file)
|
||||
return FALSE;
|
||||
|
||||
real_len = len < 0 ? strlen (text) : (gsize) len;
|
||||
|
||||
status = g_io_channel_write_chars (file, text,
|
||||
len, &bytes_written,
|
||||
error);
|
||||
|
||||
if (status != G_IO_STATUS_NORMAL || bytes_written != real_len)
|
||||
{
|
||||
g_io_channel_shutdown (file, TRUE, NULL);
|
||||
g_io_channel_unref (file);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_io_channel_shutdown (file, TRUE, NULL);
|
||||
g_io_channel_unref (file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
static gboolean
|
||||
open_uri (const char *uri, gboolean email/* = FALSE */)
|
||||
{
|
||||
g_return_val_if_fail (uri != NULL, FALSE);
|
||||
HINSTANCE h = ShellExecute (NULL, "open", uri, NULL, NULL,
|
||||
SW_SHOWNORMAL);
|
||||
return (int)h > 32;
|
||||
}
|
||||
|
||||
#else /* ! __WIN32__ */
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
typedef enum {
|
||||
KDE,
|
||||
GNOME,
|
||||
DEBIAN,
|
||||
UNKNOWN
|
||||
} Desktop;
|
||||
|
||||
|
||||
static gboolean open_uri (const char *uri,
|
||||
gboolean email /* = FALSE */)
|
||||
{
|
||||
gboolean result = FALSE;
|
||||
char **argv = NULL;
|
||||
|
||||
Desktop desktop = UNKNOWN;
|
||||
char *kfmclient = g_find_program_in_path ("kfmclient");
|
||||
char *gnome_open = g_find_program_in_path ("gnome-open");
|
||||
char *x_www_browser = g_find_program_in_path ("x-www-browser");
|
||||
|
||||
if (!email && x_www_browser &&
|
||||
g_file_test ("/etc/debian_version", G_FILE_TEST_EXISTS))
|
||||
desktop = DEBIAN;
|
||||
|
||||
if (desktop == UNKNOWN)
|
||||
{
|
||||
if (kfmclient && g_getenv ("KDE_FULL_SESSION"))
|
||||
desktop = KDE;
|
||||
else if (gnome_open && g_getenv ("GNOME_DESKTOP_SESSION_ID"))
|
||||
desktop = GNOME;
|
||||
}
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
if (desktop == UNKNOWN)
|
||||
{
|
||||
const char *wm =
|
||||
gdk_x11_screen_get_window_manager_name (gdk_screen_get_default ());
|
||||
|
||||
if (wm)
|
||||
{
|
||||
if (!g_ascii_strcasecmp (wm, "kwin") && kfmclient)
|
||||
desktop = KDE;
|
||||
else if (!g_ascii_strcasecmp (wm, "metacity") && gnome_open)
|
||||
desktop = GNOME;
|
||||
}
|
||||
}
|
||||
#endif /* GDK_WINDOWING_X11 */
|
||||
|
||||
if (desktop == UNKNOWN)
|
||||
{
|
||||
if (!email && x_www_browser)
|
||||
desktop = DEBIAN;
|
||||
else if (kfmclient)
|
||||
desktop = KDE;
|
||||
else if (gnome_open)
|
||||
desktop = GNOME;
|
||||
}
|
||||
|
||||
switch (desktop)
|
||||
{
|
||||
case KDE:
|
||||
argv = g_new0 (char*, 4);
|
||||
argv[0] = g_strdup (kfmclient);
|
||||
argv[1] = g_strdup ("exec");
|
||||
argv[2] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case GNOME:
|
||||
argv = g_new0 (char*, 3);
|
||||
argv[0] = g_strdup (gnome_open);
|
||||
argv[1] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case DEBIAN:
|
||||
argv = g_new0 (char*, 3);
|
||||
argv[0] = g_strdup (x_www_browser);
|
||||
argv[1] = g_strdup (uri);
|
||||
break;
|
||||
|
||||
case UNKNOWN:
|
||||
if (uri)
|
||||
g_warning ("could not find a way to open uri '%s'", uri);
|
||||
else
|
||||
g_warning ("could not find a way to open uri");
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
if (argv)
|
||||
{
|
||||
GError *err = NULL;
|
||||
|
||||
result = g_spawn_async (NULL, argv, NULL, (GSpawnFlags)0, NULL, NULL,
|
||||
NULL, &err);
|
||||
|
||||
if (err)
|
||||
{
|
||||
g_warning ("%s: error in g_spawn_async", G_STRLOC);
|
||||
g_warning ("%s: %s", G_STRLOC, err->message);
|
||||
g_error_free (err);
|
||||
}
|
||||
}
|
||||
|
||||
if (argv)
|
||||
g_strfreev (argv);
|
||||
|
||||
g_free (gnome_open);
|
||||
g_free (kfmclient);
|
||||
g_free (x_www_browser);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* ! __WIN32__ */
|
||||
|
||||
|
||||
gboolean
|
||||
moo_open_email (const char *address,
|
||||
const char *subject,
|
||||
const char *body)
|
||||
{
|
||||
GString *uri;
|
||||
gboolean res;
|
||||
|
||||
g_return_val_if_fail (address != NULL, FALSE);
|
||||
uri = g_string_new ("mailto:");
|
||||
g_string_append_printf (uri, "%s%s", address,
|
||||
subject || body ? "?" : "");
|
||||
if (subject)
|
||||
g_string_append_printf (uri, "subject=%s%s", subject,
|
||||
body ? "&" : "");
|
||||
if (body)
|
||||
g_string_append_printf (uri, "body=%s", body);
|
||||
|
||||
res = open_uri (uri->str, TRUE);
|
||||
g_string_free (uri, TRUE);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
moo_open_url (const char *url)
|
||||
{
|
||||
return open_uri (url, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* Windowing stuff
|
||||
*/
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
|
||||
/* TODO TODO is it 64-bits safe? */
|
||||
/* TODO TODO rewrite all of this */
|
||||
|
||||
static void
|
||||
add_xid (GtkWindow *window,
|
||||
GArray *array)
|
||||
{
|
||||
XID xid;
|
||||
|
||||
if (GTK_IS_WINDOW(window) && GTK_WIDGET(window)->window)
|
||||
{
|
||||
xid = GDK_WINDOW_XID (GTK_WIDGET(window)->window);
|
||||
g_array_append_val (array, xid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
contains (GArray *xids, XID w)
|
||||
{
|
||||
guint i;
|
||||
XID *wins = (XID*) xids->data;
|
||||
|
||||
for (i = 0; i < xids->len; ++i)
|
||||
if (wins[i] == w)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
is_minimized (Display *display, XID w)
|
||||
{
|
||||
Atom actual_type_return;
|
||||
int actual_format_return;
|
||||
gulong nitems_return;
|
||||
gulong bytes_after_return;
|
||||
Atom *data;
|
||||
int ret;
|
||||
gulong i;
|
||||
|
||||
static Atom wm_state = None;
|
||||
static Atom wm_state_hidden = None;
|
||||
|
||||
if (wm_state == None)
|
||||
{
|
||||
wm_state = XInternAtom (display, "_NET_WM_STATE", FALSE);
|
||||
wm_state_hidden = XInternAtom (display, "_NET_WM_STATE_HIDDEN", FALSE);
|
||||
}
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
ret = XGetWindowProperty (display, w,
|
||||
wm_state, 0,
|
||||
G_MAXLONG, FALSE, XA_ATOM,
|
||||
&actual_type_return,
|
||||
&actual_format_return,
|
||||
&nitems_return,
|
||||
&bytes_after_return,
|
||||
(guchar**) &data);
|
||||
|
||||
if (gdk_error_trap_pop () || ret != Success)
|
||||
{
|
||||
g_warning ("%s: oops", G_STRLOC);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!nitems_return)
|
||||
{
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (actual_type_return != XA_ATOM)
|
||||
{
|
||||
g_critical ("%s: actual_type_return != XA_WINDOW", G_STRLOC);
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < nitems_return; ++i)
|
||||
{
|
||||
if (data[i] == wm_state_hidden)
|
||||
{
|
||||
XFree (data);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static GtkWindow*
|
||||
find_by_xid (GSList *windows, XID w)
|
||||
{
|
||||
GSList *l;
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (GDK_WINDOW_XID (GTK_WIDGET(l->data)->window) == w)
|
||||
return l->data;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
GtkWindow*
|
||||
moo_get_top_window (GSList *windows)
|
||||
{
|
||||
GArray *xids;
|
||||
Display *display;
|
||||
Atom actual_type_return;
|
||||
int actual_format_return;
|
||||
gulong nitems_return;
|
||||
gulong bytes_after_return;
|
||||
XID *data;
|
||||
int ret;
|
||||
long i;
|
||||
GSList *l;
|
||||
|
||||
static Atom list_stacking_atom = None;
|
||||
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
{
|
||||
if (!GTK_IS_WINDOW (l->data))
|
||||
{
|
||||
g_critical ("%s: invalid parameter passed", G_STRLOC);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xids = g_array_new (FALSE, FALSE, sizeof (XID));
|
||||
g_slist_foreach (windows, (GFunc) add_xid, xids);
|
||||
|
||||
if (!xids->len)
|
||||
{
|
||||
g_critical ("%s: zero length array of x ids", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
display = GDK_WINDOW_XDISPLAY (GTK_WIDGET(windows->data)->window);
|
||||
|
||||
if (!display)
|
||||
{
|
||||
g_critical ("%s: !display", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (list_stacking_atom == None)
|
||||
list_stacking_atom = XInternAtom (display, "_NET_CLIENT_LIST_STACKING", FALSE);
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
ret = XGetWindowProperty (display, GDK_ROOT_WINDOW(),
|
||||
list_stacking_atom, 0,
|
||||
G_MAXLONG, FALSE, XA_WINDOW,
|
||||
&actual_type_return,
|
||||
&actual_format_return,
|
||||
&nitems_return,
|
||||
&bytes_after_return,
|
||||
(guchar**) &data);
|
||||
|
||||
if (gdk_error_trap_pop () || ret != Success)
|
||||
{
|
||||
g_critical ("%s: error in XGetWindowProperty", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!nitems_return)
|
||||
{
|
||||
g_critical ("%s: !nitems_return", G_STRLOC);
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (actual_type_return != XA_WINDOW)
|
||||
{
|
||||
g_critical ("%s: actual_type_return != XA_WINDOW", G_STRLOC);
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = nitems_return - 1; i >= 0; --i)
|
||||
{
|
||||
if (contains (xids, data[i]) && !is_minimized (display, data[i]))
|
||||
{
|
||||
XID id = data[i];
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return find_by_xid (windows, id);
|
||||
}
|
||||
}
|
||||
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
g_warning ("%s: all minimized?", G_STRLOC);
|
||||
return GTK_WINDOW (windows->data);
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
moo_window_is_hidden (GtkWindow *window)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
return is_minimized (GDK_WINDOW_XDISPLAY (GTK_WIDGET(window)->window),
|
||||
GDK_WINDOW_XID (GTK_WIDGET(window)->window));
|
||||
}
|
||||
|
||||
|
||||
#elif defined(__WIN32__)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <gdk/gdkwin32.h>
|
||||
|
||||
|
||||
#define get_handle(w) \
|
||||
gdk_win32_drawable_get_handle (GTK_WIDGET(w)->window)
|
||||
|
||||
gboolean
|
||||
moo_window_is_hidden (GtkWindow *window)
|
||||
{
|
||||
HANDLE h;
|
||||
WINDOWPLACEMENT info = {0};
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
|
||||
h = get_handle (window);
|
||||
g_return_val_if_fail (h != NULL, FALSE);
|
||||
|
||||
info.length = sizeof (WINDOWPLACEMENT);
|
||||
|
||||
if (!GetWindowPlacement (h, &info))
|
||||
{
|
||||
DWORD err = GetLastError ();
|
||||
char *msg = g_win32_error_message (err);
|
||||
g_return_val_if_fail (msg != NULL, FALSE);
|
||||
g_warning ("%s: %s", G_STRLOC, msg);
|
||||
g_free (msg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return info.showCmd == SW_MINIMIZE ||
|
||||
info.showCmd == SW_HIDE ||
|
||||
info.showCmd == SW_SHOWMINIMIZED;
|
||||
}
|
||||
|
||||
|
||||
GtkWindow*
|
||||
moo_get_top_window (GSList *windows)
|
||||
{
|
||||
GSList *l;
|
||||
HWND top = NULL;
|
||||
HWND current = NULL;
|
||||
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (l->data), NULL);
|
||||
|
||||
if (!moo_window_is_hidden (GTK_WINDOW (l->data)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!l)
|
||||
return GTK_WINDOW (windows->data);
|
||||
|
||||
top = get_handle (windows->data);
|
||||
current = top;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
current = GetNextWindow (current, GW_HWNDPREV);
|
||||
if (!current)
|
||||
break;
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (current == get_handle (l->data))
|
||||
break;
|
||||
|
||||
if (l != NULL)
|
||||
top = get_handle (l->data);
|
||||
}
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (top == get_handle (l->data))
|
||||
break;
|
||||
|
||||
g_return_val_if_fail (l != NULL, GTK_WINDOW (windows->data));
|
||||
return GTK_WINDOW (l->data);
|
||||
}
|
||||
|
||||
#else /* neither X nor WIN32 ?? */
|
||||
|
||||
GtkWindow*
|
||||
moo_get_top_window (GSList *windows)
|
||||
{
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
g_critical ("%s: don't know how to do it", G_STRLOC);
|
||||
return GTK_WINDOW (windows->data);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* TODO use gtk_window_present_with_time(), use Xlib? */
|
||||
void
|
||||
moo_window_present (GtkWindow *window)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WINDOW (window));
|
||||
gtk_window_present (window);
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
moo_window_set_icon_from_stock (GtkWindow *window,
|
||||
const char *stock_id)
|
||||
{
|
||||
#ifndef __WIN32__
|
||||
GdkPixbuf *icon;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
g_return_val_if_fail (stock_id != NULL, FALSE);
|
||||
|
||||
icon = gtk_widget_render_icon (GTK_WIDGET (window), stock_id,
|
||||
GTK_ICON_SIZE_BUTTON, 0);
|
||||
|
||||
if (icon)
|
||||
{
|
||||
gtk_window_set_icon (GTK_WINDOW (window), icon);
|
||||
gdk_pixbuf_unref (icon);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
#else /* __WIN32__ */
|
||||
return TRUE;
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
|
||||
|
||||
GtkWindow*
|
||||
moo_get_toplevel_window (void)
|
||||
{
|
||||
GList *list, *l;
|
||||
GSList *windows = NULL;
|
||||
GtkWindow *top;
|
||||
|
||||
list = gtk_window_list_toplevels ();
|
||||
|
||||
for (l = list; l != NULL; l = l->next)
|
||||
if (GTK_IS_WINDOW (l->data) && GTK_WIDGET(l->data)->window)
|
||||
windows = g_slist_prepend (windows, l->data);
|
||||
|
||||
top = moo_get_top_window (windows);
|
||||
|
||||
g_list_free (list);
|
||||
g_slist_free (windows);
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Custom log handlers
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
GtkWidget *window;
|
||||
GtkTextTag *message_tag;
|
||||
GtkTextTag *warning_tag;
|
||||
GtkTextTag *critical_tag;
|
||||
GtkTextBuffer *buf;
|
||||
GtkTextView *textview;
|
||||
GtkTextMark *insert;
|
||||
} MooLogWindow;
|
||||
|
||||
|
||||
static MooLogWindow *moo_log_window (void);
|
||||
static GtkWidget *moo_log_window_get_widget (void);
|
||||
|
||||
|
||||
static MooLogWindow*
|
||||
moo_log_window_new (void)
|
||||
{
|
||||
MooLogWindow *log;
|
||||
GtkWidget *vbox, *scrolledwindow;
|
||||
PangoFontDescription *font;
|
||||
|
||||
log = g_new (MooLogWindow, 1);
|
||||
|
||||
log->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title (GTK_WINDOW (log->window), "Log Window");
|
||||
gtk_window_set_default_size (GTK_WINDOW (log->window), 400, 300);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
gtk_widget_show (vbox);
|
||||
gtk_container_add (GTK_CONTAINER (log->window), vbox);
|
||||
|
||||
scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_widget_show (scrolledwindow);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
|
||||
GTK_WIDGET_UNSET_FLAGS (scrolledwindow, GTK_CAN_FOCUS);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow),
|
||||
GTK_SHADOW_ETCHED_IN);
|
||||
|
||||
log->textview = GTK_TEXT_VIEW (gtk_text_view_new ());
|
||||
gtk_widget_show (GTK_WIDGET (log->textview));
|
||||
gtk_container_add (GTK_CONTAINER (scrolledwindow), GTK_WIDGET (log->textview));
|
||||
GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (log->textview), GTK_CAN_FOCUS);
|
||||
gtk_text_view_set_editable (log->textview, FALSE);
|
||||
gtk_text_view_set_wrap_mode (log->textview, GTK_WRAP_WORD);
|
||||
|
||||
g_signal_connect (log->window, "delete-event",
|
||||
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
|
||||
|
||||
log->buf = gtk_text_view_get_buffer (log->textview);
|
||||
log->insert = gtk_text_buffer_get_insert (log->buf);
|
||||
log->message_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "message", "foreground", "blue", NULL);
|
||||
log->warning_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "warning", "foreground", "red", NULL);
|
||||
log->critical_tag =
|
||||
gtk_text_buffer_create_tag (log->buf, "critical", "foreground", "red",
|
||||
"weight", PANGO_WEIGHT_BOLD, NULL);
|
||||
|
||||
font = pango_font_description_from_string ("Courier New 9");
|
||||
|
||||
if (font)
|
||||
{
|
||||
gtk_widget_modify_font (GTK_WIDGET (log->textview), font);
|
||||
pango_font_description_free (font);
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_log_window_write (const gchar *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const gchar *message)
|
||||
{
|
||||
char *text;
|
||||
GtkTextTag *tag = NULL;
|
||||
GtkTextIter end;
|
||||
MooLogWindow *log = moo_log_window ();
|
||||
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION))
|
||||
{
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
if (log_domain)
|
||||
text = g_strdup_printf ("%s: %s\n", log_domain, message);
|
||||
else
|
||||
text = g_strdup_printf ("%s\n", message);
|
||||
|
||||
if (flags >= G_LOG_LEVEL_MESSAGE)
|
||||
tag = log->message_tag;
|
||||
else if (flags >= G_LOG_LEVEL_WARNING)
|
||||
tag = log->warning_tag;
|
||||
else
|
||||
tag = log->critical_tag;
|
||||
|
||||
gtk_text_buffer_get_end_iter (log->buf, &end);
|
||||
gtk_text_buffer_insert_with_tags (log->buf, &end, text, -1, tag, NULL);
|
||||
gtk_text_view_scroll_mark_onscreen (log->textview, log->insert);
|
||||
}
|
||||
|
||||
|
||||
static MooLogWindow*
|
||||
moo_log_window (void)
|
||||
{
|
||||
static MooLogWindow *log = NULL;
|
||||
if (!log) log = moo_log_window_new ();
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
static GtkWidget*
|
||||
moo_log_window_get_widget (void)
|
||||
{
|
||||
MooLogWindow *log = moo_log_window ();
|
||||
return log->window;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_log_window_show (void)
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (moo_log_window_get_widget ()));
|
||||
}
|
||||
|
||||
void
|
||||
moo_log_window_hide (void)
|
||||
{
|
||||
gtk_widget_hide (moo_log_window_get_widget ());
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#define PLEASE_REPORT \
|
||||
"Please report it to emuntyan@sourceforge.net and provide "\
|
||||
"steps needed to reproduce this error."
|
||||
|
||||
#ifdef __WIN32__
|
||||
void
|
||||
moo_show_fatal_error (const char *logdomain, const char *logmsg)
|
||||
{
|
||||
char *msg = NULL;
|
||||
|
||||
if (logdomain)
|
||||
msg = g_strdup_printf ("Fatal GGAP error:\n---\n%s: %s\n---\n"
|
||||
PLEASE_REPORT, logdomain, logmsg);
|
||||
else
|
||||
msg = g_strdup_printf ("Fatal GGAP error:\n---\n%s\n---\n"
|
||||
PLEASE_REPORT, logmsg);
|
||||
|
||||
MessageBox (NULL, msg, "Error", MB_ICONERROR | MB_APPLMODAL | MB_SETFOREGROUND);
|
||||
|
||||
g_free (msg);
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
static void
|
||||
log_func_file (const char *log_domain,
|
||||
G_GNUC_UNUSED GLogLevelFlags flags,
|
||||
const char *message,
|
||||
gpointer filename)
|
||||
{
|
||||
static gboolean firsttime = TRUE;
|
||||
static char *name = NULL;
|
||||
FILE *logfile;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION))
|
||||
{
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
if (firsttime)
|
||||
{
|
||||
name = g_strdup ((char*)filename);
|
||||
logfile = fopen (name, "w+");
|
||||
firsttime = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
logfile = fopen (name, "a+");
|
||||
}
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
if (log_domain)
|
||||
fprintf (logfile, "%s: %s\r\n", log_domain, message);
|
||||
else
|
||||
fprintf (logfile, "%s\r\n", message);
|
||||
|
||||
fclose (logfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO ??? */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
log_func_silent (G_GNUC_UNUSED const gchar *log_domain,
|
||||
G_GNUC_UNUSED GLogLevelFlags flags,
|
||||
G_GNUC_UNUSED const gchar *message,
|
||||
G_GNUC_UNUSED gpointer data_unused)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
if (flags & (G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION))
|
||||
{
|
||||
moo_show_fatal_error (log_domain, message);
|
||||
return;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
|
||||
|
||||
typedef void (*LogFunc) (const gchar *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const gchar *message,
|
||||
gpointer data);
|
||||
|
||||
|
||||
static void
|
||||
set_handler (LogFunc func, gpointer data)
|
||||
{
|
||||
#if !GLIB_CHECK_VERSION(2,6,0)
|
||||
g_log_set_handler ("Glib",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler ("Gtk",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler ("Pango",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler ("Moo",
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
g_log_set_handler (NULL,
|
||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
|
||||
func, data);
|
||||
#else /* GLIB_CHECK_VERSION(2,6,0) */
|
||||
g_log_set_default_handler (func, data);
|
||||
#endif /* GLIB_CHECK_VERSION(2,6,0) */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_set_log_func_window (int show)
|
||||
{
|
||||
if (show) moo_log_window_show ();
|
||||
set_handler ((LogFunc)moo_log_window_write, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_set_log_func_file (const char *log_file)
|
||||
{
|
||||
g_return_if_fail (log_file != NULL);
|
||||
set_handler (log_func_file, (char*)log_file);
|
||||
}
|
||||
|
||||
void
|
||||
moo_set_log_func (int show_log)
|
||||
{
|
||||
if (!show_log)
|
||||
{
|
||||
set_handler (log_func_silent, NULL);
|
||||
}
|
||||
#ifdef __WIN32__
|
||||
else
|
||||
{
|
||||
moo_set_log_func_window (FALSE);
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* mooutils-misc.h
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef __MOO_UTILS_MISC_H__
|
||||
#define __MOO_UTILS_MISC_H__
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
gboolean moo_save_file_utf8 (const char *name,
|
||||
const char *text,
|
||||
gssize len,
|
||||
GError **error);
|
||||
int moo_unlink (const char *filename);
|
||||
|
||||
gboolean moo_open_url (const char *url);
|
||||
gboolean moo_open_email (const char *address,
|
||||
const char *subject,
|
||||
const char *body);
|
||||
|
||||
|
||||
gboolean moo_window_is_hidden (GtkWindow *window);
|
||||
void moo_window_present (GtkWindow *window);
|
||||
GtkWindow *moo_get_top_window (GSList *windows);
|
||||
GtkWindow *moo_get_toplevel_window (void);
|
||||
|
||||
gboolean moo_window_set_icon_from_stock (GtkWindow *window,
|
||||
const char *stock_id);
|
||||
|
||||
|
||||
void moo_log_window_show (void);
|
||||
void moo_log_window_hide (void);
|
||||
|
||||
void moo_log_window_write (const char *log_domain,
|
||||
GLogLevelFlags flags,
|
||||
const char *message);
|
||||
|
||||
|
||||
void moo_set_log_func_window (gboolean show);
|
||||
void moo_set_log_func_file (const char *log_file);
|
||||
void moo_set_log_func (gboolean show_log);
|
||||
#ifdef __WIN32__
|
||||
void moo_show_fatal_error (const char *logdomain,
|
||||
const char *logmsg);
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MOO_UTILS_MISC_H__ */
|
|
@ -1,328 +0,0 @@
|
|||
/*
|
||||
* mooutils/moowin.c
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#include "mooutils/moowin.h"
|
||||
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
|
||||
/* TODO TODO is it 64-bits safe? */
|
||||
/* TODO TODO rewrite all of this */
|
||||
|
||||
static void add_xid (GtkWindow *window,
|
||||
GArray *array)
|
||||
{
|
||||
XID xid;
|
||||
if (window && GTK_WIDGET(window)->window) {
|
||||
xid = GDK_WINDOW_XID (GTK_WIDGET(window)->window);
|
||||
g_array_append_val (array, xid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean contains (GArray *xids, XID w)
|
||||
{
|
||||
guint i;
|
||||
XID *wins = (XID*) xids->data;
|
||||
for (i = 0; i < xids->len; ++i)
|
||||
if (wins[i] == w)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static gboolean is_minimized (Display *display, XID w)
|
||||
{
|
||||
Atom actual_type_return;
|
||||
int actual_format_return;
|
||||
gulong nitems_return;
|
||||
gulong bytes_after_return;
|
||||
Atom *data;
|
||||
int ret;
|
||||
gulong i;
|
||||
|
||||
static Atom wm_state = None;
|
||||
static Atom wm_state_hidden = None;
|
||||
if (wm_state == None) {
|
||||
wm_state = XInternAtom (display, "_NET_WM_STATE", FALSE);
|
||||
wm_state_hidden = XInternAtom (display, "_NET_WM_STATE_HIDDEN", FALSE);
|
||||
}
|
||||
|
||||
gdk_error_trap_push ();
|
||||
ret = XGetWindowProperty (display, w,
|
||||
wm_state, 0,
|
||||
G_MAXLONG, FALSE, XA_ATOM,
|
||||
&actual_type_return,
|
||||
&actual_format_return,
|
||||
&nitems_return,
|
||||
&bytes_after_return,
|
||||
(guchar**) &data);
|
||||
g_return_val_if_fail (!gdk_error_trap_pop () && ret == Success, FALSE);
|
||||
|
||||
if (!nitems_return) {
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (actual_type_return != XA_ATOM) {
|
||||
g_critical ("%s: actual_type_return != XA_WINDOW", G_STRLOC);
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < nitems_return; ++i)
|
||||
if (data[i] == wm_state_hidden) {
|
||||
XFree (data);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
XFree (data);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static GtkWindow *find_by_xid (GSList *windows, XID w)
|
||||
{
|
||||
GSList *l;
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (GDK_WINDOW_XID (GTK_WIDGET(l->data)->window) == w)
|
||||
return l->data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
GtkWindow *moo_get_top_window (GSList *windows)
|
||||
{
|
||||
GArray *xids;
|
||||
Display *display;
|
||||
Atom actual_type_return;
|
||||
int actual_format_return;
|
||||
gulong nitems_return;
|
||||
gulong bytes_after_return;
|
||||
XID *data;
|
||||
int ret;
|
||||
long i;
|
||||
|
||||
static Atom list_stacking_atom = None;
|
||||
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
|
||||
xids = g_array_new (FALSE, FALSE, sizeof (XID));
|
||||
g_slist_foreach (windows, (GFunc) add_xid, xids);
|
||||
|
||||
if (!xids->len) {
|
||||
g_critical ("%s: zero length array of x ids", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
display = GDK_WINDOW_XDISPLAY (GTK_WIDGET(windows->data)->window);
|
||||
if (!display) {
|
||||
g_critical ("%s: !display", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (list_stacking_atom == None)
|
||||
list_stacking_atom = XInternAtom (display, "_NET_CLIENT_LIST_STACKING", FALSE);
|
||||
|
||||
gdk_error_trap_push ();
|
||||
ret = XGetWindowProperty (display, GDK_ROOT_WINDOW(),
|
||||
list_stacking_atom, 0,
|
||||
G_MAXLONG, FALSE, XA_WINDOW,
|
||||
&actual_type_return,
|
||||
&actual_format_return,
|
||||
&nitems_return,
|
||||
&bytes_after_return,
|
||||
(guchar**) &data);
|
||||
if (gdk_error_trap_pop () || ret != Success) {
|
||||
g_critical ("%s: error in XGetWindowProperty", G_STRLOC);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!nitems_return) {
|
||||
g_critical ("%s: !nitems_return", G_STRLOC);
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (actual_type_return != XA_WINDOW) {
|
||||
g_critical ("%s: actual_type_return != XA_WINDOW", G_STRLOC);
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = nitems_return - 1; i >= 0; --i)
|
||||
if (contains (xids, data[i]) && !is_minimized (display, data[i]))
|
||||
{
|
||||
XID id = data[i];
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
return find_by_xid (windows, id);
|
||||
}
|
||||
|
||||
XFree (data);
|
||||
g_array_free (xids, TRUE);
|
||||
g_warning ("%s: all minimized?", G_STRLOC);
|
||||
return GTK_WINDOW (windows->data);
|
||||
}
|
||||
|
||||
|
||||
gboolean moo_window_is_hidden (GtkWindow *window)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
return is_minimized (GDK_WINDOW_XDISPLAY (GTK_WIDGET(window)->window),
|
||||
GDK_WINDOW_XID (GTK_WIDGET(window)->window));
|
||||
}
|
||||
|
||||
|
||||
#elif defined(__WIN32__)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <gdk/gdkwin32.h>
|
||||
|
||||
|
||||
#define get_handle(w) \
|
||||
gdk_win32_drawable_get_handle (GTK_WIDGET(w)->window)
|
||||
|
||||
gboolean moo_window_is_hidden (GtkWindow *window)
|
||||
{
|
||||
HANDLE h;
|
||||
WINDOWPLACEMENT info = {0};
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
|
||||
|
||||
h = get_handle (window);
|
||||
g_return_val_if_fail (h != NULL, FALSE);
|
||||
|
||||
info.length = sizeof (WINDOWPLACEMENT);
|
||||
if (!GetWindowPlacement (h, &info)) {
|
||||
DWORD err = GetLastError ();
|
||||
char *msg = g_win32_error_message (err);
|
||||
g_return_val_if_fail (msg != NULL, FALSE);
|
||||
g_warning ("%s: %s", G_STRLOC, msg);
|
||||
g_free (msg);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return info.showCmd == SW_MINIMIZE ||
|
||||
info.showCmd == SW_HIDE ||
|
||||
info.showCmd == SW_SHOWMINIMIZED;
|
||||
}
|
||||
|
||||
|
||||
GtkWindow *moo_get_top_window (GSList *windows)
|
||||
{
|
||||
GSList *l;
|
||||
HWND top = NULL;
|
||||
HWND current = NULL;
|
||||
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (!moo_window_is_hidden (GTK_WINDOW (l->data)))
|
||||
break;
|
||||
if (!l)
|
||||
return GTK_WINDOW (windows->data);
|
||||
|
||||
top = get_handle (windows->data);
|
||||
current = top;
|
||||
while (TRUE) {
|
||||
current = GetNextWindow (current, GW_HWNDPREV);
|
||||
if (!current)
|
||||
break;
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (current == get_handle (l->data))
|
||||
break;
|
||||
if (l != NULL)
|
||||
top = get_handle (l->data);
|
||||
}
|
||||
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
if (top == get_handle (l->data))
|
||||
break;
|
||||
g_return_val_if_fail (l != NULL, GTK_WINDOW (windows->data));
|
||||
return GTK_WINDOW (l->data);
|
||||
}
|
||||
|
||||
#else /* neither X nor WIN32 */
|
||||
|
||||
GtkWindow *moo_get_top_window (GSList *windows)
|
||||
{
|
||||
g_return_val_if_fail (windows != NULL, NULL);
|
||||
g_critical ("%s: don't know how to do it", G_STRLOC);
|
||||
return GTK_WINDOW (windows->data);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* TODO use gtk_window_present_with_time(), use Xlib? */
|
||||
void
|
||||
moo_window_present (GtkWindow *window)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WINDOW (window));
|
||||
gtk_window_present (window);
|
||||
}
|
||||
|
||||
|
||||
gboolean moo_window_set_icon_from_stock (GtkWindow *window,
|
||||
const char *stock_id)
|
||||
{
|
||||
#ifndef __WIN32__
|
||||
GdkPixbuf *icon;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window) && stock_id != NULL, FALSE);
|
||||
icon = gtk_widget_render_icon (GTK_WIDGET (window), stock_id,
|
||||
GTK_ICON_SIZE_BUTTON, 0);
|
||||
|
||||
if (icon) {
|
||||
gtk_window_set_icon (GTK_WINDOW (window), icon);
|
||||
gdk_pixbuf_unref (icon);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
#else /* __WIN32__ */
|
||||
return TRUE;
|
||||
#endif /* __WIN32__ */
|
||||
}
|
||||
|
||||
|
||||
GtkWindow *moo_get_toplevel_window (void)
|
||||
{
|
||||
GList *list, *l;
|
||||
GSList *windows = NULL;
|
||||
GtkWindow *top;
|
||||
|
||||
list = gtk_window_list_toplevels ();
|
||||
|
||||
for (l = list; l != NULL; l = l->next)
|
||||
if (GTK_IS_WINDOW (l->data) && GTK_WIDGET(l->data)->window)
|
||||
windows = g_slist_prepend (windows, l->data);
|
||||
|
||||
top = moo_get_top_window (windows);
|
||||
|
||||
g_list_free (list);
|
||||
g_slist_free (windows);
|
||||
return top;
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* mooutils/moowin.h
|
||||
*
|
||||
* Copyright (C) 2004-2005 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef MOOUTILS_MOOWIN_H
|
||||
#define MOOUTILS_MOOWIN_H
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
gboolean moo_window_is_hidden (GtkWindow *window);
|
||||
void moo_window_present (GtkWindow *window);
|
||||
GtkWindow *moo_get_top_window (GSList *windows);
|
||||
GtkWindow *moo_get_toplevel_window (void);
|
||||
|
||||
gboolean moo_window_set_icon_from_stock (GtkWindow *window,
|
||||
const char *stock_id);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOOUTILS_MOOWIN_H */
|
|
@ -23,7 +23,7 @@ if MOO_BUILD_EDIT
|
|||
medit = medit
|
||||
endif
|
||||
if MOO_BUILD_TERM
|
||||
noinst_PROGRAMS += mterm #termbuffer
|
||||
# noinst_PROGRAMS += mterm termbuffer
|
||||
endif
|
||||
if MOO_BUILD_UTILS
|
||||
# noinst_PROGRAMS += markup miniglade
|
||||
|
|
Loading…
Reference in New Issue