Re: [AD] desktop resolution (2) |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
* Eric Botcazou (ebotcazou@xxxxxxxxxx) wrote:
> - Beos: todo (currently NULL method)
Patch to implement support is attached.
Also attached is a patch to output messages in a dialog box only if the
program was invoked from the Tracker (on BeOS), printing only to the
console if the program was launched from the command line. Someone had
asked for this earlier, and I found this kind of detection implemented
in VIM, so I adopted it for Allegro.
I'm not very familiar with standard patch-making protocol, so if there's
anything wrong with the way the patches are made, please let me know.
Joshua
--
Joshua Haberman <joshua@xxxxxxxxxx>
University of Puget Sound <joshua@xxxxxxxxxx>
http://www.reverberate.org <jhaberman@xxxxxxxxxx>
diff -ru ./allegro/src/beos/bsysapi.cpp ./allegro-local/src/beos/bsysapi.cpp
--- ./allegro/src/beos/bsysapi.cpp Fri Feb 16 23:12:06 2001
+++ ./allegro-local/src/beos/bsysapi.cpp Tue Apr 24 19:44:36 2001
@@ -348,6 +348,15 @@
+extern "C" int be_sys_get_desktop_resolution(int *width, int *height)
+{
+ BScreen screen(be_allegro_screen);
+ *width = screen.Frame().IntegerWidth() + 1;
+ *height = screen.Frame().IntegerHeight() + 1;
+
+ return 1;
+}
+
extern "C" void be_sys_yield_timeslice(void)
{
snooze(YIELD_TIME);
diff -ru ./allegro/src/beos/bsystem.c ./allegro-local/src/beos/bsystem.c
--- ./allegro/src/beos/bsystem.c Tue Apr 24 18:26:41 2001
+++ ./allegro-local/src/beos/bsystem.c Tue Apr 24 18:46:15 2001
@@ -54,7 +54,7 @@
be_sys_remove_display_switch_cb, // AL_METHOD(int, remove_display_switch_callback, (AL_METHOD(void, cb, (void))));
NULL, // AL_METHOD(void, display_switch_lock, (int lock));
be_sys_desktop_color_depth, // AL_METHOD(int, desktop_color_depth, (void));
- NULL, // AL_METHOD(int, get_desktop_resolution, (int *width, int *height));
+ be_sys_get_desktop_resolution, // AL_METHOD(int, get_desktop_resolution, (int *width, int *height));
be_sys_yield_timeslice, // AL_METHOD(void, yield_timeslice, (void));
NULL, // AL_METHOD(_DRIVER_INFO *, gfx_drivers, (void));
NULL, // AL_METHOD(_DRIVER_INFO *, digi_drivers, (void));
diff -ru ./allegro/include/allegro/aintbeos.h ./allegro-local/include/allegro/aintbeos.h
--- ./allegro/include/allegro/aintbeos.h Fri Feb 16 23:12:06 2001
+++ ./allegro-local/include/allegro/aintbeos.h Tue Apr 24 19:24:22 2001
@@ -50,6 +50,7 @@
void be_sys_set_window_close_hook(void (*proc)(void));
void be_sys_message(AL_CONST char *msg);
int be_sys_desktop_color_depth(void);
+int be_sys_get_desktop_resolution(int *width, int *height);
void be_sys_yield_timeslice(void);
int be_sys_set_display_switch_mode(int mode);
int be_sys_set_display_switch_cb(int dir, void (*cb)(void));
--- ./allegro/src/beos/bsysapi.cpp Tue Apr 24 20:10:54 2001
+++ ./allegro-local/src/beos/bsysapi.cpp Tue Apr 24 20:49:38 2001
@@ -309,6 +309,28 @@
+/* invoked_from_terminal():
+ * Try to determine if we were run from a terminal, or from the Tracker.
+ * There's no API call that will report this authoritatively, so we have to
+ * guess--this particular heuristic is taken from the vim source code.
+ */
+static bool invoked_from_terminal()
+{
+ if(!isatty(0)) {
+ struct stat stat_stdin, stat_dev_null;
+
+ if(fstat(0, &stat_stdin) == -1 ||
+ stat("/dev/null", &stat_dev_null) == -1 ||
+ (stat_stdin.st_dev == stat_dev_null.st_dev &&
+ stat_stdin.st_ino == stat_dev_null.st_ino))
+ return false;
+ }
+
+ return true;
+}
+
+
+
extern "C" void be_sys_message(AL_CONST char *msg)
{
char filename[MAXPATHLEN];
@@ -317,11 +339,13 @@
get_executable_name(filename, sizeof(filename));
title = get_filename(filename);
- fprintf(stderr, "%s: %s", title, msg);
-
- BAlert *alert = new BAlert(title, msg, "Okay");
- alert->SetShortcut(0, B_ESCAPE);
- alert->Go();
+ if(invoked_from_terminal())
+ fprintf(stderr, "%s: %s", title, msg);
+ else {
+ BAlert *alert = new BAlert(title, msg, "Okay");
+ alert->SetShortcut(0, B_ESCAPE);
+ alert->Go();
+ }
}