Re: [AD] allegro_message under X |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Elias Pschernig a écrit :
> It looks fine with xmessage. Btw, I think "gdialog" is actually called
> "gtk-shell". But the only difference is that the "Ok" button follows
> the theme. Same for kdialog I assume. So maybe we should just always
> use xmessage? I mean, given it is an Allegro program which definitely
> won't follow neither Qt nor GTK theme - I think having proper line
> breaks is more important than the look of the OK button.
Hmm, kdialog makes a huge difference on my system, it not just the OK
button :-) But it seems bare x apps such as xmessage look abnormally ugly on
my system. So I agree it's best to just always use xmessage.
Here is another patch, to use instead of the previous one. This time only
xmessage is tried, and I added a few more command line options to allow
closing the dialogs with ENTER.
Also, I used fork/exec/wait as suggested by Stepan Roh. It should be simpler,
faster and safer, all at once :-) The only thing is that I'm not too
confident about my use of fork/exec/waitpid. It seems to work, but it might
need better error checking; and I'm not too clear about the interaction with
ressources that allegro might uses, such as signals.
> > I suppose the window is needed for keyboard input, but maybe it could be
> > hidden by set_gfx_mode(GFX_TEXT), or made very small... ?
>
> Hm. Yes, this indeed is bad. I think, GFX_TEXT should hide the window.
> Does the attached patch work for you?
Yes, the patch does hide the window. However, you then stop getting keyboard
input, as expected. This is allowed by the docs, but is there no way around
it ? Does a window really need to be visible in order to get keyboard input ?
--
Julien Cugnière
--- src/x/xsystem.c.old 2004-10-23 17:42:29.000000000 +0200
+++ src/x/xsystem.c 2004-10-23 22:19:43.107263112 +0200
@@ -24,6 +24,8 @@
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
@@ -37,6 +39,7 @@
static void _xwin_sysdrv_exit(void);
static void _xwin_sysdrv_set_window_title(AL_CONST char *name);
static int _xwin_sysdrv_set_close_button_callback(void (*proc)(void));
+static void _xwin_sysdrv_message(AL_CONST char *msg);
static int _xwin_sysdrv_display_switch_mode(int mode);
static int _xwin_sysdrv_desktop_color_depth(void);
static int _xwin_sysdrv_get_desktop_resolution(int *width, int *height);
@@ -65,7 +68,7 @@
_unix_find_resource,
_xwin_sysdrv_set_window_title,
_xwin_sysdrv_set_close_button_callback,
- NULL, /* message */
+ _xwin_sysdrv_message,
NULL, /* assert */
NULL, /* save_console_state */
NULL, /* restore_console_state */
@@ -274,6 +277,40 @@
+/* _xwin_sysdrv_message:
+ * Displays a message. Uses xmessage if possible, and stdout if not.
+ */
+static void _xwin_sysdrv_message(AL_CONST char *msg)
+{
+ int ret, status;
+ char *buf = malloc(ALLEGRO_MESSAGE_SIZE);
+ char *msg2 = uconvert(msg, U_CURRENT, buf, U_ASCII_CP, ALLEGRO_MESSAGE_SIZE);
+
+ pid_t pid = fork();
+ switch (pid) {
+ case -1: /* fork error */
+ fputs(msg2, stdout);
+ break;
+
+ case 0: /* child process */
+ execlp("xmessage", "xmessage", "-buttons", "OK", "-default", "OK", "-center", msg2, NULL);
+ /* if execution reaches here, it means execlp failed */
+ fputs(msg2, stdout);
+ exit(-1);
+ break;
+
+ default: /* parent process */
+ ret = waitpid(pid, &status, 0);
+ if (ret != pid || !WIFEXITED(status) || WEXITSTATUS(status) != 101)
+ fputs(msg2, stdout);
+ break;
+ }
+
+ free(buf);
+}
+
+
+
/* _xwin_sysdrv_gfx_drivers:
* Get the list of graphics drivers.
*/