[Spice-commits] Branch '0.8' - 3 commits - client/application.cpp client/application.h client/common.h client/red_client.cpp client/windows
Alon Levy
alon at kemper.freedesktop.org
Thu Jan 27 07:27:40 PST 2011
client/application.cpp | 90 ++++++++++++++++++++++++++++----------------
client/application.h | 5 +-
client/common.h | 11 ++++-
client/red_client.cpp | 4 +
client/windows/platform.cpp | 36 +++++++++++++----
5 files changed, 103 insertions(+), 43 deletions(-)
New commits:
commit 7b4e4f278a2f836a5afd2eb8d12288324be12151
Author: Alon Levy <alevy at redhat.com>
Date: Thu Jan 27 12:13:20 2011 +0200
client/windows: don't allocate console unless required
diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index 1676000..fc6fb2e 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -1106,6 +1106,7 @@ void Platform::on_clipboard_release()
}
static bool has_console = false;
+static BOOL parent_console;
static void create_console()
{
@@ -1117,27 +1118,44 @@ static void create_console()
return;
}
- AllocConsole();
+ parent_console = AttachConsole(-1 /* parent */);
+
+ if (!parent_console) {
+ AllocConsole();
+ }
+
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
int hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- FILE * fp = _fdopen(hConHandle, "w");
- *stdout = *fp;
+ FILE * fp;
+ /* _open_osfhandle can fail, for instance this will fail:
+ start /wait spicec.exe --help | more
+ however this actually works:
+ cmd /c spicec --help | more
+ */
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "w");
+ *stdout = *fp;
+ }
h = GetStdHandle(STD_INPUT_HANDLE);
hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "r");
- *stdin = *fp;
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "r");
+ *stdin = *fp;
+ }
h = GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle((intptr_t)h, _O_TEXT);
- fp = _fdopen(hConHandle, "w");
- *stderr = *fp;
+ if (hConHandle != -1) {
+ fp = _fdopen(hConHandle, "w");
+ *stderr = *fp;
+ }
has_console = true;
HWND consol_window = GetConsoleWindow();
- if (consol_window) {
+ if (consol_window && !parent_console) {
SetForegroundWindow(consol_window);
}
}
@@ -1146,7 +1164,7 @@ class ConsoleWait {
public:
~ConsoleWait()
{
- if (has_console) {
+ if (has_console && !parent_console) {
Platform::term_printf("\n\nPress any key to exit...");
_getch();
}
commit fe3b3d39379f03aa627c9d2020abfd60b372e2af
Author: Alon Levy <alevy at redhat.com>
Date: Thu Jan 27 12:12:41 2011 +0200
client: fix broken vs2008 build
diff --git a/client/common.h b/client/common.h
index e1c149c..522f22b 100644
--- a/client/common.h
+++ b/client/common.h
@@ -26,7 +26,11 @@
#include <errno.h>
#endif
-#include <spice/types.h>
+#define __STDC_FORMAT_MACROS
+#ifndef _WIN32
+#include <inttypes.h>
+#endif
+
#include <stdio.h>
#include <string>
#include <vector>
@@ -62,6 +66,11 @@
#define RED64
#endif
+#if defined(_WIN32) && !defined(PRIu64)
+#define PRIu64 "I64u"
+#endif
+
+#include <spice/types.h>
#include "red_types.h"
#endif
diff --git a/client/red_client.cpp b/client/red_client.cpp
index 0a53d2e..549e9dd 100644
--- a/client/red_client.cpp
+++ b/client/red_client.cpp
@@ -24,6 +24,10 @@
#include "debug.h"
#include "marshallers.h"
+#ifndef INFINITY
+#define INFINITY HUGE
+#endif
+
#ifdef __GNUC__
typedef struct __attribute__ ((__packed__)) OldRedMigrationBegin {
#else
commit bfdd2371f806cff9f80cee0ab4d1b5a809dd82ca
Author: Alon Levy <alevy at redhat.com>
Date: Wed Jan 26 01:52:45 2011 +0200
client: --help should not need platform initialization
separate initialization into before command line parsing and after,
call later only if command line parsing succeeds (in particular, it
"fails" if --help is given).
diff --git a/client/application.cpp b/client/application.cpp
index 13ff8fa..bfe3ff8 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -377,14 +377,6 @@ Application::Application()
#endif
{
DBG(0, "");
- Platform::set_process_loop(*this);
- init_monitors();
- memset(_keyboard_state, 0, sizeof(_keyboard_state));
- init_menu();
- _main_screen = get_screen(0);
-
- Platform::set_event_listener(this);
- Platform::set_display_mode_listner(this);
_commands_map["toggle-fullscreen"] = APP_CMD_TOGGLE_FULL_SCREEN;
_commands_map["release-cursor"] = APP_CMD_RELEASE_CAPTURE;
@@ -435,37 +427,37 @@ Application::Application()
_sticky_info.key = REDKEY_INVALID;
_sticky_info.timer.reset(new StickyKeyTimer());
-#ifdef USE_GUI
- _gui.reset(new GUI(*this, DISCONNECTED));
- _gui_timer.reset(new GUITimer(*_gui.get()));
- activate_interval_timer(*_gui_timer, 1000 / 30);
-#ifdef GUI_DEMO
- _gui_test_timer.reset(new TestTimer(*this));
- activate_interval_timer(*_gui_test_timer, 1000 * 30);
-#endif
-#endif // USE_GUI
for (int i = SPICE_CHANNEL_MAIN; i < SPICE_END_CHANNEL; i++) {
_peer_con_opt[i] = RedPeer::ConnectionOptions::CON_OP_BOTH;
}
+ memset(_keyboard_state, 0, sizeof(_keyboard_state));
}
Application::~Application()
{
#ifdef USE_GUI
- deactivate_interval_timer(*_gui_timer);
+ if (*_gui_timer != NULL) {
+ deactivate_interval_timer(*_gui_timer);
+ }
#ifdef GUI_DEMO
- deactivate_interval_timer(*_gui_test_timer);
+ if (*_gui_test_timer != NULL) {
+ deactivate_interval_timer(*_gui_test_timer);
+ }
#endif
destroyed_gui_barriers();
- _gui->set_screen(NULL);
+ if (_gui.get() != NULL) {
+ _gui->set_screen(NULL);
+ }
#endif // USE_GUI
if (_info_layer->screen()) {
_main_screen->detach_layer(*_info_layer);
}
- _main_screen->unref();
- destroy_monitors();
+ if (_main_screen != NULL) {
+ _main_screen->unref();
+ destroy_monitors();
+ }
#ifdef USE_SMARTCARD
delete _smartcard_options;
#endif
@@ -2196,13 +2188,12 @@ void Application::register_channels()
#endif
}
-bool Application::process_cmd_line(int argc, char** argv)
+bool Application::process_cmd_line(int argc, char** argv, bool &full_screen)
{
std::string host = "";
int sport = -1;
int port = -1;
bool auto_display_res = false;
- bool full_screen = false;
std::string password;
DisplaySetting display_setting;
@@ -2232,11 +2223,12 @@ bool Application::process_cmd_line(int argc, char** argv)
#endif
};
+ full_screen = false;
+
#ifdef USE_GUI
if (argc == 1) {
_gui_mode = GUI_MODE_FULL;
register_channels();
- _main_screen->show(true, NULL);
return true;
}
#endif // USE_GUI
@@ -2454,11 +2446,6 @@ bool Application::process_cmd_line(int argc, char** argv)
_client.set_auto_display_res(auto_display_res);
_client.set_display_setting(display_setting);
- if (full_screen) {
- enter_full_screen();
- } else {
- _main_screen->show(true, NULL);
- }
return true;
}
@@ -2558,26 +2545,65 @@ void Application::init_globals()
#ifdef WIN32
gdi_canvas_init();
#endif
+}
+/* seperated from init_globals to allow --help to work
+ * faster and not require X on linux. */
+void Application::init_platform_globals()
+{
Platform::init();
RedWindow::init();
}
-void Application::cleanup_globals()
+void Application::init_remainder()
+{
+ Platform::set_process_loop(*this);
+ init_monitors();
+ init_menu();
+ _main_screen = get_screen(0);
+
+ Platform::set_event_listener(this);
+ Platform::set_display_mode_listner(this);
+
+#ifdef USE_GUI
+ _gui.reset(new GUI(*this, DISCONNECTED));
+ _gui_timer.reset(new GUITimer(*_gui.get()));
+ activate_interval_timer(*_gui_timer, 1000 / 30);
+#ifdef GUI_DEMO
+ _gui_test_timer.reset(new TestTimer(*this));
+ activate_interval_timer(*_gui_test_timer, 1000 * 30);
+#endif
+#endif // USE_GUI
+}
+
+void Application::cleanup_platform_globals()
{
RedWindow::cleanup();
}
+void Application::cleanup_globals()
+{
+}
+
int Application::main(int argc, char** argv, const char* version_str)
{
int ret;
+ bool full_screen;
init_globals();
LOG_INFO("starting %s", version_str);
std::auto_ptr<Application> app(new Application());
AutoAbort auto_abort(*app.get());
- if (app->process_cmd_line(argc, argv)) {
+ if (app->process_cmd_line(argc, argv, full_screen)) {
+ init_platform_globals();
+ app->init_remainder();
+ if (full_screen) {
+ app->enter_full_screen();
+ } else {
+ app->_main_screen->show(true, NULL);
+ }
ret = app->run();
+ cleanup_platform_globals();
} else {
ret = app->_exit_code;
}
diff --git a/client/application.h b/client/application.h
index f9bbd53..4133dfe 100644
--- a/client/application.h
+++ b/client/application.h
@@ -290,7 +290,7 @@ private:
bool set_disabled_display_effects(CmdLineParser& parser, char *val, const char* arg0,
DisplaySetting& disp_setting);
void on_cmd_line_invalid_arg(const char* arg0, const char* what, const char* val);
- bool process_cmd_line(int argc, char** argv);
+ bool process_cmd_line(int argc, char** argv, bool& full_screen);
void register_channels();
void abort();
void init_menu();
@@ -343,7 +343,10 @@ private:
static void init_logger();
static void init_globals();
+ static void init_platform_globals();
+ static void cleanup_platform_globals();
static void cleanup_globals();
+ void init_remainder();
friend class DisconnectedEvent;
friend class ConnectionErrorEvent;
More information about the Spice-commits
mailing list