summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/lib/osdlib_win32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/modules/lib/osdlib_win32.cpp')
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp127
1 files changed, 47 insertions, 80 deletions
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index 75218574aff..c5792f0307d 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -21,6 +21,7 @@
#include "osdlib.h"
#include "osdcomm.h"
#include "osdcore.h"
+#include "strconv.h"
#ifdef OSD_WINDOWS
#include "winutf8.h"
@@ -101,21 +102,6 @@ void osd_process_kill(void)
}
//============================================================
-// osd_num_processors
-//============================================================
-
-int osd_get_num_processors(void)
-{
- SYSTEM_INFO info;
-
- // otherwise, fetch the info from the system
- GetSystemInfo(&info);
-
- // max out at 4 for now since scaling above that seems to do poorly
- return MIN(info.dwNumberOfProcessors, 4);
-}
-
-//============================================================
// osd_malloc
//============================================================
@@ -257,93 +243,74 @@ void osd_break_into_debugger(const char *message)
}
//============================================================
-// GLOBAL VARIABLES
-//============================================================
-
-static osd_ticks_t ticks_per_second = 0;
-static osd_ticks_t suspend_ticks = 0;
-static BOOL using_qpc = TRUE;
-
-
-
-//============================================================
-// osd_ticks
+// get_clipboard_text_by_format
//============================================================
-osd_ticks_t osd_ticks(void)
+static char *get_clipboard_text_by_format(UINT format, char *(*convert)(LPCVOID data))
{
- LARGE_INTEGER performance_count;
+ char *result = NULL;
+ HANDLE data_handle;
+ LPVOID data;
- // if we're suspended, just return that
- if (suspend_ticks != 0)
- return suspend_ticks;
-
- // if we have a per second count, just go for it
- if (ticks_per_second != 0)
+ // check to see if this format is available
+ if (IsClipboardFormatAvailable(format))
{
- // QueryPerformanceCounter if we can
- if (using_qpc)
+ // open the clipboard
+ if (OpenClipboard(NULL))
{
- QueryPerformanceCounter(&performance_count);
- return (osd_ticks_t)performance_count.QuadPart - suspend_ticks;
+ // try to access clipboard data
+ data_handle = GetClipboardData(format);
+ if (data_handle != NULL)
+ {
+ // lock the data
+ data = GlobalLock(data_handle);
+ if (data != NULL)
+ {
+ // invoke the convert
+ result = (*convert)(data);
+
+ // unlock the data
+ GlobalUnlock(data_handle);
+ }
+ }
+
+ // close out the clipboard
+ CloseClipboard();
}
-
- // otherwise, fall back to timeGetTime
- else
- return (osd_ticks_t)timeGetTime() - suspend_ticks;
}
-
- // if not, we have to determine it
- using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0);
- if (using_qpc)
- ticks_per_second = (osd_ticks_t)performance_count.QuadPart;
- else
- ticks_per_second = 1000;
-
- // call ourselves to get the first value
- return osd_ticks();
+ return result;
}
-
//============================================================
-// osd_ticks_per_second
+// convert_wide
//============================================================
-osd_ticks_t osd_ticks_per_second(void)
+static char *convert_wide(LPCVOID data)
{
- if (ticks_per_second == 0)
- osd_ticks();
- return ticks_per_second;
+ return utf8_from_wstring((LPCWSTR) data);
}
//============================================================
-// osd_sleep
+// convert_ansi
//============================================================
-void osd_sleep(osd_ticks_t duration)
+static char *convert_ansi(LPCVOID data)
{
- DWORD msec;
-
- // make sure we've computed ticks_per_second
- if (ticks_per_second == 0)
- (void)osd_ticks();
+ return utf8_from_astring((LPCSTR) data);
+}
- // convert to milliseconds, rounding down
- msec = (DWORD)(duration * 1000 / ticks_per_second);
+//============================================================
+// osd_get_clipboard_text
+//============================================================
- // only sleep if at least 2 full milliseconds
- if (msec >= 2)
- {
- HANDLE current_thread = GetCurrentThread();
- int old_priority = GetThreadPriority(current_thread);
+char *osd_get_clipboard_text(void)
+{
+ // try to access unicode text
+ char *result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
- // take a couple of msecs off the top for good measure
- msec -= 2;
+ // try to access ANSI text
+ if (result == nullptr)
+ result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
- // bump our thread priority super high so that we get
- // priority when we need it
- SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL);
- Sleep(msec);
- SetThreadPriority(current_thread, old_priority);
- }
+ return result;
}