comparison system/Init.cpp @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children 67b1b8cec8c0
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include <QApplication>
17 #include <QFont>
18
19 #include <iostream>
20
21 #include "System.h"
22
23 #ifdef Q_WS_X11
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/Xatom.h>
27 #include <X11/SM/SMlib.h>
28
29 static int handle_x11_error(Display *dpy, XErrorEvent *err)
30 {
31 char errstr[256];
32 XGetErrorText(dpy, err->error_code, errstr, 256);
33 if (err->error_code != BadWindow) {
34 std::cerr << "Sonic Visualiser: X Error: "
35 << errstr << " " << int(err->error_code)
36 << "\nin major opcode: "
37 << int(err->request_code) << std::endl;
38 }
39 return 0;
40 }
41 #endif
42
43 #ifdef Q_WS_WIN32
44
45 #include <fcntl.h>
46 #include <windows.h>
47
48 // Set default file open mode to binary
49 //#undef _fmode
50 //int _fmode = _O_BINARY;
51
52 void redirectStderr()
53 {
54 HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
55 if (!stderrHandle) return;
56
57 AllocConsole();
58
59 CONSOLE_SCREEN_BUFFER_INFO info;
60 GetConsoleScreenBufferInfo(stderrHandle, &info);
61 info.dwSize.Y = 1000;
62 SetConsoleScreenBufferSize(stderrHandle, info.dwSize);
63
64 int h = _open_osfhandle((long)stderrHandle, _O_TEXT);
65 if (h) {
66 FILE *fd = _fdopen(h, "w");
67 if (fd) {
68 *stderr = *fd;
69 setvbuf(stderr, NULL, _IONBF, 0);
70 }
71 }
72 }
73
74 #endif
75
76 extern void svSystemSpecificInitialisation()
77 {
78 #ifdef Q_WS_X11
79 XSetErrorHandler(handle_x11_error);
80 #endif
81
82 #ifdef Q_WS_WIN32
83 redirectStderr();
84 QFont fn = qApp->font();
85 fn.setFamily("Tahoma");
86 qApp->setFont(fn);
87 #else
88 #ifdef Q_WS_X11
89 QFont fn = qApp->font();
90 fn.setPointSize(fn.pointSize() + 2);
91 qApp->setFont(fn);
92 #endif
93 #endif
94 }
95
96
97