From 08e70fc82ebfae4cc11ad6eee0dc3197b1d1672b Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 28 May 2018 14:33:52 +0530 Subject: freeze library proted to linux (Debugging and testing) --- common/linux/freeze.cpp | 243 +++++++++++++++++++++++++++--------------------- common/linux/freeze.h | 4 +- 2 files changed, 139 insertions(+), 108 deletions(-) diff --git a/common/linux/freeze.cpp b/common/linux/freeze.cpp index 0d27ca7..453ae82 100644 --- a/common/linux/freeze.cpp +++ b/common/linux/freeze.cpp @@ -18,13 +18,16 @@ */ void FreezeWindowPosF(HWND hwnd, char *subKey, char *name) { - if (-1 == system("mkdir -p /usr/share/ldmicro")) + char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35); + if(!moveToKeyLocatin) return; - - std::ofstream Register("binConf", std::ios::binary | std::ios::trunc); - if (!Register.is_open()) + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) return; - + free(moveToKeyLocatin); + char *keyName = (char *)malloc(strlen(name) + 30); if(!keyName) return; @@ -34,39 +37,53 @@ void FreezeWindowPosF(HWND hwnd, char *subKey, char *name) int val; sprintf(keyName, "%s_width", name); - gtk_window_get_size(GTK_WINDOW(hwnd), &val, NULL); - newKey.name = keyName; + std::ofstream Register(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_size(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &val, NULL); newKey.type = 'i'; - newKey.val = val; + newKey.val.i = val; Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); sprintf(keyName, "%s_height", name); - gtk_window_get_size(GTK_WINDOW(hwnd), NULL, &val); - newKey.name = keyName; + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_size(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), NULL, &val); newKey.type = 'i'; - newKey.val = val; + newKey.val.i = val; Register.write((char*) &newKey, sizeof(newKey)); - + Register.close(); sprintf(keyName, "%s_posX", name); - gtk_window_get_position(GTK_WINDOW(hwnd), &val, NULL); - newKey.name = keyName; + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_position(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &val, NULL); newKey.type = 'i'; - newKey.val = val; + newKey.val.i = val; Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); sprintf(keyName, "%s_posY", name); - gtk_window_get_position(GTK_WINDOW(hwnd), NULL, &val); - newKey.name = keyName; + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_position(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), NULL, &val); newKey.type = 'i'; - newKey.val = val; + newKey.val.i = val; Register.write((char*) &newKey, sizeof(newKey)); - + Register.close(); + sprintf(keyName, "%s_maximized", name); - newKey.name = keyName; + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; newKey.type = 'b'; - newKey.val = gtk_window_is_maximized(GTK_WINDOW(hwnd)); + newKey.val.b = gtk_window_is_maximized(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd)))); Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); free(keyName); } @@ -82,69 +99,68 @@ static void Clamp(LONG *v, LONG min, LONG max) */ void ThawWindowPosF(HWND hwnd, char *subKey, char *name) { - HKEY software; - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS) + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) return; - - HKEY sub; - if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS) + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) return; - + free(moveToKeyLocatin); + char *keyName = (char *)malloc(strlen(name) + 30); if(!keyName) return; - DWORD l; - RECT r; + Key newkey1, newkey2; - sprintf(keyName, "%s_left", name); - l = sizeof(DWORD); - if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.left), &l) != ERROR_SUCCESS) + /// set size + sprintf(keyName, "%s_width", name); + std::ifstream Register(keyName, std::ios::binary); + if (!Register.is_open()) return; + Register.read((char*) &newKey1, sizeof(newKey1)); + Register.close(); - sprintf(keyName, "%s_right", name); - l = sizeof(DWORD); - if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.right), &l) != ERROR_SUCCESS) + sprintf(keyName, "%s_height", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) return; + Register.read((char*) &newKey2, sizeof(newKey2)); + Register.close(); + if (newKey1.type == 'i' && newKey2.type == 'i') + gtk_window_resize(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &newKey1.val.i, &newKey2.val.i); + - sprintf(keyName, "%s_top", name); - l = sizeof(DWORD); - if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.top), &l) != ERROR_SUCCESS) + /// set position + sprintf(keyName, "%s_posX", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) return; + Register.read((char*) &newKey1, sizeof(newKey1)); + Register.close(); - sprintf(keyName, "%s_bottom", name); - l = sizeof(DWORD); - if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.bottom), &l) != ERROR_SUCCESS) + sprintf(keyName, "%s_posY", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) return; + Register.read((char*) &newKey2, sizeof(newKey2)); + Register.close(); + if (newKey1.type == 'i' && newKey2.type == 'i') + gtk_window_move(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &newKey1.val.i, &newKey2.val.i); + sprintf(keyName, "%s_maximized", name); - DWORD v; - l = sizeof(DWORD); - if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&v, &l) != ERROR_SUCCESS) - return; - if(v) - ShowWindow(hwnd, SW_MAXIMIZE); - - RECT dr; - GetWindowRect(GetDesktopWindow(), &dr); - - // If it somehow ended up off-screen, then put it back. - Clamp(&(r.left), dr.left, dr.right); - Clamp(&(r.right), dr.left, dr.right); - Clamp(&(r.top), dr.top, dr.bottom); - Clamp(&(r.bottom), dr.top, dr.bottom); - if(r.right - r.left < 100) { - r.left -= 300; r.right += 300; - } - if(r.bottom - r.top < 100) { - r.top -= 300; r.bottom += 300; - } - Clamp(&(r.left), dr.left, dr.right); - Clamp(&(r.right), dr.left, dr.right); - Clamp(&(r.top), dr.top, dr.bottom); - Clamp(&(r.bottom), dr.top, dr.bottom); - - MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey, sizeof(newKey)); + Register.close(); + if (newKey.type == 'b') + if (newKey.val.b) + gtk_window_maximize(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd)))); + + + /// gtk_window_move handles off-screen window placement free(keyName); } @@ -154,16 +170,22 @@ void ThawWindowPosF(HWND hwnd, char *subKey, char *name) */ void FreezeDWORDF(DWORD val, char *subKey, char *name) { - HKEY software; - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS) - return; - - HKEY sub; - if(RegCreateKeyEx(software, subKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &sub, NULL) != ERROR_SUCCESS) + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) return; - - if(RegSetValueEx(sub, name, 0, REG_DWORD, (BYTE *)&val, sizeof(DWORD)) != ERROR_SUCCESS) + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) return; + free(moveToKeyLocatin); + + Key newKey; + newKey.type = 'D'; + newKey.val.D = val; + std::ofstream Register(name, std::ios::binary | std::ios::trunc); + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); } /* @@ -171,20 +193,26 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name) */ DWORD ThawDWORDF(DWORD val, char *subKey, char *name) { - HKEY software; - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS) + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) return val; - - HKEY sub; - if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS) + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) return val; + free(moveToKeyLocatin); + + Key newKey; - DWORD l = sizeof(DWORD); - DWORD v; - if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)&v, &l) != ERROR_SUCCESS) + std::ifstream Register(name, std::ios::binary); + Register.read((char*) &newKey, sizeof(newKey)); + Register.close(); + if(Register.bad()) return val; - return v; + if(newKey.type == 'D') + return newKey.val.D; + else + return val; } /* @@ -192,16 +220,20 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name) */ void FreezeStringF(char *val, char *subKey, char *name) { - HKEY software; - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS) - return; - - HKEY sub; - if(RegCreateKeyEx(software, subKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &sub, NULL) != ERROR_SUCCESS) - return; - - if(RegSetValueEx(sub, name, 0, REG_SZ, (BYTE *)val, strlen(val)+1) != ERROR_SUCCESS) - return; + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return val; + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return val; + free(moveToKeyLocatin); + + std::ofstream Register(name, std::ios::trunc); + Register << strlen(val)+1 << "\n"; + Register << val; + Register.close(); } /* @@ -209,20 +241,19 @@ void FreezeStringF(char *val, char *subKey, char *name) */ void ThawStringF(char *val, int max, char *subKey, char *name) { - HKEY software; - if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS) + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) return; - - HKEY sub; - if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS) + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) return; + free(moveToKeyLocatin); - DWORD l = max; - if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)val, &l) != ERROR_SUCCESS) + std::ifstream Register(name); + int l; + Register >> l; + if (l >= max) return; - if(l >= (DWORD)max) return; - - val[l] = '\0'; - return; + Register >> val; } diff --git a/common/linux/freeze.h b/common/linux/freeze.h index 0827f6e..7aabec7 100644 --- a/common/linux/freeze.h +++ b/common/linux/freeze.h @@ -10,6 +10,8 @@ #ifndef __FREEZE_H #define __FREEZE_H +#define LDMICRO_REGISTER "/usr/share/ldmicro" + #ifndef FREEZE_SUBKEY #error must define FREEZE_SUBKEY to a string uniquely identifying the app #endif @@ -35,14 +37,12 @@ void ThawStringF(char *val, int max, char *subKey, char *name); typedef union regKeyVal{ int i; float f; - double d; bool b; DWORD D; } KeyVal; typedef struct regKeys{ - char name[15]; char type; KeyVal val; } Key; -- cgit From 5c01aef5fd87870b63511f17bd50405a0df08a3b Mon Sep 17 00:00:00 2001 From: Rr42 Date: Tue, 29 May 2018 10:46:19 +0530 Subject: Freeze library updated and renamed to freezeLD (working) --- common/linux/freeze.cpp | 259 ----------------------------------- common/linux/freeze.h | 50 ------- ldmicro/CMakeLists.txt | 81 +++++------ ldmicro/draw_outputdev.cpp | 2 +- ldmicro/includes/linuxUI/linuxLD.h | 60 -------- ldmicro/includes/linuxUI/linuxUI.h | 19 --- ldmicro/ldmicro.cpp | 4 +- ldmicro/lib/freezeLD/CMakeLists.txt | 4 + ldmicro/lib/freezeLD/freezeLD.cpp | 265 ++++++++++++++++++++++++++++++++++++ ldmicro/lib/freezeLD/freezeLD.h | 52 +++++++ ldmicro/lib/linuxUI/CMakeLists.txt | 3 + ldmicro/lib/linuxUI/linuxLD.h | 61 +++++++++ ldmicro/lib/linuxUI/linuxUI.cpp | 18 +++ ldmicro/lib/linuxUI/linuxUI.h | 19 +++ ldmicro/linuxUI.cpp | 18 --- 15 files changed, 468 insertions(+), 447 deletions(-) delete mode 100644 common/linux/freeze.cpp delete mode 100644 common/linux/freeze.h delete mode 100644 ldmicro/includes/linuxUI/linuxLD.h delete mode 100644 ldmicro/includes/linuxUI/linuxUI.h create mode 100644 ldmicro/lib/freezeLD/CMakeLists.txt create mode 100644 ldmicro/lib/freezeLD/freezeLD.cpp create mode 100644 ldmicro/lib/freezeLD/freezeLD.h create mode 100644 ldmicro/lib/linuxUI/CMakeLists.txt create mode 100644 ldmicro/lib/linuxUI/linuxLD.h create mode 100644 ldmicro/lib/linuxUI/linuxUI.cpp create mode 100644 ldmicro/lib/linuxUI/linuxUI.h delete mode 100644 ldmicro/linuxUI.cpp diff --git a/common/linux/freeze.cpp b/common/linux/freeze.cpp deleted file mode 100644 index 453ae82..0000000 --- a/common/linux/freeze.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * A library for storing parameters in a key file - * - * This library is an analog to the windows freeze library - * developed by Jonathan Westhues. - * - * R Ramana, 2018 - */ -#include "freeze.h" -#include -#include -#include -#include -#include - -/* - * store a window's position in the registry, or fail silently if the registry calls don't work - */ -void FreezeWindowPosF(HWND hwnd, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35); - if(!moveToKeyLocatin) - return; - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); - system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return; - free(moveToKeyLocatin); - - char *keyName = (char *)malloc(strlen(name) + 30); - if(!keyName) - return; - - Key newkey; - - int val; - - sprintf(keyName, "%s_width", name); - std::ofstream Register(keyName, std::ios::binary | std::ios::trunc); - if (!Register.is_open()) - return; - gtk_window_get_size(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &val, NULL); - newKey.type = 'i'; - newKey.val.i = val; - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); - - sprintf(keyName, "%s_height", name); - Register.open(keyName, std::ios::binary | std::ios::trunc); - if (!Register.is_open()) - return; - gtk_window_get_size(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), NULL, &val); - newKey.type = 'i'; - newKey.val.i = val; - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); - - sprintf(keyName, "%s_posX", name); - Register.open(keyName, std::ios::binary | std::ios::trunc); - if (!Register.is_open()) - return; - gtk_window_get_position(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &val, NULL); - newKey.type = 'i'; - newKey.val.i = val; - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); - - sprintf(keyName, "%s_posY", name); - Register.open(keyName, std::ios::binary | std::ios::trunc); - if (!Register.is_open()) - return; - gtk_window_get_position(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), NULL, &val); - newKey.type = 'i'; - newKey.val.i = val; - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); - - sprintf(keyName, "%s_maximized", name); - Register.open(keyName, std::ios::binary | std::ios::trunc); - if (!Register.is_open()) - return; - newKey.type = 'b'; - newKey.val.b = gtk_window_is_maximized(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd)))); - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); - - free(keyName); -} - -static void Clamp(LONG *v, LONG min, LONG max) -{ - if(*v < min) *v = min; - if(*v > max) *v = max; -} - -/* - * retrieve a window's position from the registry, or do nothing if there is no info saved - */ -void ThawWindowPosF(HWND hwnd, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); - if(!moveToKeyLocatin) - return; - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return; - free(moveToKeyLocatin); - - char *keyName = (char *)malloc(strlen(name) + 30); - if(!keyName) - return; - - Key newkey1, newkey2; - - /// set size - sprintf(keyName, "%s_width", name); - std::ifstream Register(keyName, std::ios::binary); - if (!Register.is_open()) - return; - Register.read((char*) &newKey1, sizeof(newKey1)); - Register.close(); - - sprintf(keyName, "%s_height", name); - Register.open(keyName, std::ios::binary); - if (!Register.is_open()) - return; - Register.read((char*) &newKey2, sizeof(newKey2)); - Register.close(); - if (newKey1.type == 'i' && newKey2.type == 'i') - gtk_window_resize(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &newKey1.val.i, &newKey2.val.i); - - - /// set position - sprintf(keyName, "%s_posX", name); - Register.open(keyName, std::ios::binary); - if (!Register.is_open()) - return; - Register.read((char*) &newKey1, sizeof(newKey1)); - Register.close(); - - sprintf(keyName, "%s_posY", name); - Register.open(keyName, std::ios::binary); - if (!Register.is_open()) - return; - Register.read((char*) &newKey2, sizeof(newKey2)); - Register.close(); - if (newKey1.type == 'i' && newKey2.type == 'i') - gtk_window_move(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd))), &newKey1.val.i, &newKey2.val.i); - - - sprintf(keyName, "%s_maximized", name); - Register.open(keyName, std::ios::binary); - if (!Register.is_open()) - return; - Register.read((char*) &newKey, sizeof(newKey)); - Register.close(); - if (newKey.type == 'b') - if (newKey.val.b) - gtk_window_maximize(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(hwnd)))); - - - /// gtk_window_move handles off-screen window placement - - free(keyName); -} - -/* - * store a DWORD setting in the registry - */ -void FreezeDWORDF(DWORD val, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); - if(!moveToKeyLocatin) - return; - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); - system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return; - free(moveToKeyLocatin); - - Key newKey; - newKey.type = 'D'; - newKey.val.D = val; - std::ofstream Register(name, std::ios::binary | std::ios::trunc); - Register.write((char*) &newKey, sizeof(newKey)); - Register.close(); -} - -/* - * retrieve a DWORD setting, or return the default if that setting is unavailable - */ -DWORD ThawDWORDF(DWORD val, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); - if(!moveToKeyLocatin) - return val; - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return val; - free(moveToKeyLocatin); - - Key newKey; - - std::ifstream Register(name, std::ios::binary); - Register.read((char*) &newKey, sizeof(newKey)); - Register.close(); - if(Register.bad()) - return val; - - if(newKey.type == 'D') - return newKey.val.D; - else - return val; -} - -/* - * store a string setting in the registry - */ -void FreezeStringF(char *val, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); - if(!moveToKeyLocatin) - return val; - sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); - system(moveToKeyLocatin); - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return val; - free(moveToKeyLocatin); - - std::ofstream Register(name, std::ios::trunc); - Register << strlen(val)+1 << "\n"; - Register << val; - Register.close(); -} - -/* - * retrieve a string setting, or return the default if that setting is unavailable - */ -void ThawStringF(char *val, int max, char *subKey, char *name) -{ - char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); - if(!moveToKeyLocatin) - return; - sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); - if (-1 == system(moveToKeyLocatin)) - return; - free(moveToKeyLocatin); - - std::ifstream Register(name); - int l; - Register >> l; - if (l >= max) - return; - Register >> val; -} - diff --git a/common/linux/freeze.h b/common/linux/freeze.h deleted file mode 100644 index 7aabec7..0000000 --- a/common/linux/freeze.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * A library for storing parameters in a key file - * - * This library is an analog to the windows freeze library - * developed by Jonathan Westhues. - * - * R Ramana, 2018 - */ - -#ifndef __FREEZE_H -#define __FREEZE_H - -#define LDMICRO_REGISTER "/usr/share/ldmicro" - -#ifndef FREEZE_SUBKEY -#error must define FREEZE_SUBKEY to a string uniquely identifying the app -#endif - -#define FreezeWindowPos(hwnd) FreezeWindowPosF(hwnd, FREEZE_SUBKEY, #hwnd) -void FreezeWindowPosF(HWND hWnd, char *subKey, char *name); - -#define ThawWindowPos(hwnd) ThawWindowPosF(hwnd, FREEZE_SUBKEY, #hwnd) -void ThawWindowPosF(HWND hWnd, char *subKey, char *name); - -#define FreezeDWORD(val) FreezeDWORDF(val, FREEZE_SUBKEY, #val) -void FreezeDWORDF(DWORD val, char *subKey, char *name); - -#define ThawDWORD(val) val = ThawDWORDF(val, FREEZE_SUBKEY, #val) -DWORD ThawDWORDF(DWORD val, char *subKey, char *name); - -#define FreezeString(val) FreezeStringF(val, FREEZE_SUBKEY, #val) -void FreezeStringF(char *val, char *subKey, char *name); - -#define ThawString(val, max) ThawStringF(val, max, FREEZE_SUBKEY, #val) -void ThawStringF(char *val, int max, char *subKey, char *name); - -typedef union regKeyVal{ - int i; - float f; - bool b; - DWORD D; -} KeyVal; - - -typedef struct regKeys{ - char type; - KeyVal val; -} Key; - -#endif diff --git a/ldmicro/CMakeLists.txt b/ldmicro/CMakeLists.txt index 1becba8..239cb87 100644 --- a/ldmicro/CMakeLists.txt +++ b/ldmicro/CMakeLists.txt @@ -7,9 +7,13 @@ IF(WIN32) add_definitions(-D__WIN32__) ENDIF(WIN32) +IF (MSVC) + MESSAGE( FATAL_ERROR "Cannot build for MacOS, exiting" ) + add_definitions(-D__MSVC__) +ENDIF (MSVC) + IF(UNIX) add_definitions(-D__UNIX__) - include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../common/linux") MESSAGE( STATUS "Performing system check.." ) MESSAGE( STATUS "Identifing bitness of the platform.." ) @@ -21,45 +25,46 @@ IF(UNIX) MESSAGE( STATUS "Bitness of the platform: " 36) endif() MESSAGE( STATUS "Performing system check - done" ) -ENDIF(UNIX) - -IF (MSVC) - MESSAGE( FATAL_ERROR "Cannot build for MacOS, exiting" ) - add_definitions(-D__MSVC__) -ENDIF (MSVC) - -MESSAGE ( STATUS "Searching for GTK+3.0..." ) -find_package (PkgConfig REQUIRED) -pkg_check_modules (GTK3 REQUIRED gtk+-3.0) -# Version control -set (LDMicro_VERSION_MAJOR 1) -set (LDMicro_VERSION_MINOR 0) + MESSAGE ( STATUS "Searching for GTK+3.0..." ) + find_package (PkgConfig REQUIRED) + pkg_check_modules (GTK3 REQUIRED gtk+-3.0) -# configure a header file to pass some of the CMake settings -# to the source code -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/includes") -set(PROJECT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/includes") -CONFIGURE_FILE ( - "${PROJECT_INCLUDE_DIR}/ldmicroVC.h.in" - "${PROJECT_INCLUDE_DIR}/ldmicroVC.h" -) -MESSAGE ( STATUS " PROJECT_INCLUDE_DIR: " ${PROJECT_INCLUDE_DIR} ) + # Version control + set (LDMicro_VERSION_MAJOR 1) + set (LDMicro_VERSION_MINOR 0) + # configure a header file to pass some of the CMake settings + # to the source code + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/linuxUI") + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/lib/freezeLD") + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/includes") + set(PROJECT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/includes") + CONFIGURE_FILE ( + "${PROJECT_INCLUDE_DIR}/ldmicroVC.h.in" + "${PROJECT_INCLUDE_DIR}/ldmicroVC.h" + ) + MESSAGE ( STATUS " PROJECT_INCLUDE_DIR: " ${PROJECT_INCLUDE_DIR} ) -# Add GTK3 include files if GTK3 is found -IF ( GTK3_FOUND ) - include_directories (${GTK3_INCLUDE_DIRS}) - link_directories (${GTK3_LIBRARY_DIRS}) - add_definitions (${GTK3_CFLAGS_OTHER}) - link_libraries (${GTK3_LIBRARIES}) - MESSAGE ( STATUS " GTK3_INCLUDE_DIR: " ${GTK3_INCLUDE_DIRS} ) - MESSAGE ( STATUS " GTK3_LIBRARIES: " ${GTK3_LIBRARIES} ) -ENDIF ( GTK3_FOUND) -## Dummy compile and install to test linuxUI -## to compile LDmicro uncomment the below 2 line2 -#add_executable (LDMicro ldmicro.cpp)# miscutil.cpp draw_outputdev.cpp) -# install (TARGETS LDMicro DESTINATION bin) -add_executable (linuxUI testMain.cpp) -install (TARGETS linuxUI DESTINATION bin) + # Add GTK3 include files if GTK3 is found + IF ( GTK3_FOUND ) + include_directories (${GTK3_INCLUDE_DIRS}) + link_directories (${GTK3_LIBRARY_DIRS}) + add_definitions (${GTK3_CFLAGS_OTHER}) + link_libraries (${GTK3_LIBRARIES}) + MESSAGE ( STATUS " GTK3_INCLUDE_DIR: " ${GTK3_INCLUDE_DIRS} ) + MESSAGE ( STATUS " GTK3_LIBRARIES: " ${GTK3_LIBRARIES} ) + ENDIF ( GTK3_FOUND ) + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/lib/linuxUI") + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/lib/freezeLD") + + ## Dummy compile and install to test linuxUI + ## to compile LDmicro uncomment the below 2 line2 + #add_executable (LDMicro ldmicro.cpp)# miscutil.cpp draw_outputdev.cpp) + # install (TARGETS LDMicro DESTINATION bin) + add_executable (testMain testMain.cpp) + target_link_libraries (testMain LinuxUI) + target_link_libraries (testMain FreezeLD) + install (TARGETS testMain DESTINATION bin) +ENDIF(UNIX) \ No newline at end of file diff --git a/ldmicro/draw_outputdev.cpp b/ldmicro/draw_outputdev.cpp index bc4a7ef..0d6f3cd 100644 --- a/ldmicro/draw_outputdev.cpp +++ b/ldmicro/draw_outputdev.cpp @@ -25,7 +25,7 @@ // Ported to linus by: R Ramana, 2018 //----------------------------------------------------------------------------- -#include "linuxUI/linuxUI.h" +#include "linuxUI.h" #include #include diff --git a/ldmicro/includes/linuxUI/linuxLD.h b/ldmicro/includes/linuxUI/linuxLD.h deleted file mode 100644 index 53194e1..0000000 --- a/ldmicro/includes/linuxUI/linuxLD.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __LINUX_LD__ -#define __LINUX_LD__ - -#include "linuxUI/linuxUI.h" - -/// common windows referances for linux - -/// definitions -#define MAX_PATH PATH_MAX -/// CALLBACK or __stdcall os defined empty -#define CALLBACK - -/// typedefs -//typedef int64_t __int64; -typedef bool BOOL; -typedef unsigned char BYTE; -typedef unsigned int DWORD; - -/// all handles will hold a GtkWindow* type -typedef void* PVOID; -typedef GtkWidget* HANDLE; -typedef HANDLE HINSTANCE; -typedef HANDLE HWID; -typedef HANDLE HDC; -typedef HANDLE HMENU; - -typedef GtkWindow* HWND; - -typedef GtkApplication* HAPP; - -/// Check if system is x64 or x86 -#if defined(__UNIX64) -typedef uint64_t UINT_PTR; -#else -typedef unsigned int UINT_PTR; -#endif - -typedef UINT_PTR WPARAM; -typedef unsigned int UINT; - -/// custom classes -class COLORREF : public GdkRGBA{ - public: - COLORREF() - { - this->red = 0.0; - this->green = 0.0; - this->blue = 0.0; - this->alpha = 1.0; - } - COLORREF(int r, int g, int b) - { - this->red = r/255.0; - this->green = g/255.0; - this->blue = b/255.0; - this->alpha = 1.0; - } -}; - -#endif diff --git a/ldmicro/includes/linuxUI/linuxUI.h b/ldmicro/includes/linuxUI/linuxUI.h deleted file mode 100644 index 01b7af2..0000000 --- a/ldmicro/includes/linuxUI/linuxUI.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __LINUX_UI__ -#define __LINUX_UI__ - -/// includes -#include -#include -#include -#include -#include "linuxUI/linuxLD.h" - -/// version control -#define LDMicro_VERSION_MAJOR 1 -#define LDMicro_VERSION_MINOR 0 - -/// functions -BOOL isFocus(HWND); -COLORREF RGB(int, int, int); - -#endif \ No newline at end of file diff --git a/ldmicro/ldmicro.cpp b/ldmicro/ldmicro.cpp index e7e3f17..cc0a525 100644 --- a/ldmicro/ldmicro.cpp +++ b/ldmicro/ldmicro.cpp @@ -24,7 +24,7 @@ // most of the UI logic relating to the main window. // Jonathan Westhues, Oct 2004 //----------------------------------------------------------------------------- -#include "linuxUI/linuxUI.h" +#include "linuxUI.h" #include #include @@ -36,7 +36,7 @@ HINSTANCE Instance; -HWND MainWindow; +HWID MainWindow; HDC Hdc; // parameters used to capture the mouse when implementing our totally non- diff --git a/ldmicro/lib/freezeLD/CMakeLists.txt b/ldmicro/lib/freezeLD/CMakeLists.txt new file mode 100644 index 0000000..761f348 --- /dev/null +++ b/ldmicro/lib/freezeLD/CMakeLists.txt @@ -0,0 +1,4 @@ +project( FreezeLD ) + +add_library(FreezeLD freezeLD.cpp) +target_link_libraries(FreezeLD LinuxUI) diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp new file mode 100644 index 0000000..5241af1 --- /dev/null +++ b/ldmicro/lib/freezeLD/freezeLD.cpp @@ -0,0 +1,265 @@ +/* + * A library for storing parameters in a key file + * + * This library is an analog to the windows freeze library + * developed by Jonathan Westhues. + * + * R Ramana, 2018 + */ +#include "linuxUI.h" +#include "freezeLD.h" +#include +#include +#include +#include + +/* + * store a window's position in the registry, or fail silently if the registry calls don't work + */ +void FreezeWindowPosF(HWID hwid, char *subKey, char *name) +{ + g_print("freezing"); + char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35); + if(!moveToKeyLocatin) + return; + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return; + free(moveToKeyLocatin); + + char *keyName = (char *)malloc(strlen(name) + 30); + if(!keyName) + return; + + Key newKey; + + int val; + g_print("get width"); + sprintf(keyName, "%s_width", name); + std::ofstream Register(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_size(GTK_WINDOW(hwid), &val, NULL); + newKey.type = 'i'; + newKey.val.i = val; + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); + + g_print("get height"); + sprintf(keyName, "%s_height", name); + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_size(GTK_WINDOW(hwid), NULL, &val); + newKey.type = 'i'; + newKey.val.i = val; + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); + + g_print("get posX"); + sprintf(keyName, "%s_posX", name); + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_position(GTK_WINDOW(hwid), &val, NULL); + newKey.type = 'i'; + newKey.val.i = val; + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); + + g_print("get posY"); + sprintf(keyName, "%s_posY", name); + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + gtk_window_get_position(GTK_WINDOW(hwid), NULL, &val); + newKey.type = 'i'; + newKey.val.i = val; + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); + + g_print("get max"); + sprintf(keyName, "%s_maximized", name); + Register.open(keyName, std::ios::binary | std::ios::trunc); + if (!Register.is_open()) + return; + newKey.type = 'b'; + newKey.val.b = gtk_window_is_maximized(GTK_WINDOW(hwid)); + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); + + free(keyName); + g_print("freezed"); +} + +static void Clamp(LONG *v, LONG min, LONG max) +{ + if(*v < min) *v = min; + if(*v > max) *v = max; +} + +/* + * retrieve a window's position from the registry, or do nothing if there is no info saved + */ +void ThawWindowPosF(HWID hwid, char *subKey, char *name) +{ + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return; + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return; + free(moveToKeyLocatin); + + char *keyName = (char *)malloc(strlen(name) + 30); + if(!keyName) + return; + + Key newKey1, newKey2; + + /// set size + sprintf(keyName, "%s_width", name); + std::ifstream Register(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey1, sizeof(newKey1)); + Register.close(); + + sprintf(keyName, "%s_height", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey2, sizeof(newKey2)); + Register.close(); + if (newKey1.type == 'i' && newKey2.type == 'i') + gtk_window_resize(GTK_WINDOW(hwid), newKey1.val.i, newKey2.val.i); + + + /// set position + sprintf(keyName, "%s_posX", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey1, sizeof(newKey1)); + Register.close(); + + sprintf(keyName, "%s_posY", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey2, sizeof(newKey2)); + Register.close(); + if (newKey1.type == 'i' && newKey2.type == 'i') + gtk_window_move(GTK_WINDOW(hwid), newKey1.val.i, newKey2.val.i); + + + sprintf(keyName, "%s_maximized", name); + Register.open(keyName, std::ios::binary); + if (!Register.is_open()) + return; + Register.read((char*) &newKey1, sizeof(newKey1)); + Register.close(); + if (newKey1.type == 'b') + if (newKey1.val.b) + gtk_window_maximize(GTK_WINDOW(hwid)); + + + /// gtk_window_move handles off-screen window placement + + free(keyName); +} + +/* + * store a DWORD setting in the registry + */ +void FreezeDWORDF(DWORD val, char *subKey, char *name) +{ + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return; + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return; + free(moveToKeyLocatin); + + Key newKey; + newKey.type = 'D'; + newKey.val.D = val; + std::ofstream Register(name, std::ios::binary | std::ios::trunc); + Register.write((char*) &newKey, sizeof(newKey)); + Register.close(); +} + +/* + * retrieve a DWORD setting, or return the default if that setting is unavailable + */ +DWORD ThawDWORDF(DWORD val, char *subKey, char *name) +{ + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return val; + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return val; + free(moveToKeyLocatin); + + Key newKey; + + std::ifstream Register(name, std::ios::binary); + Register.read((char*) &newKey, sizeof(newKey)); + Register.close(); + if(Register.bad()) + return val; + + if(newKey.type == 'D') + return newKey.val.D; + else + return val; +} + +/* + * store a string setting in the registry + */ +void FreezeStringF(char *val, char *subKey, char *name) +{ + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return; + sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey); + system(moveToKeyLocatin); + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return; + free(moveToKeyLocatin); + + std::ofstream Register(name, std::ios::trunc); + Register << strlen(val)+1 << "\n"; + Register << val; + Register.close(); +} + +/* + * retrieve a string setting, or return the default if that setting is unavailable + */ +void ThawStringF(char *val, int max, char *subKey, char *name) +{ + char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30); + if(!moveToKeyLocatin) + return; + sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey); + if (-1 == system(moveToKeyLocatin)) + return; + free(moveToKeyLocatin); + + std::ifstream Register(name); + int l; + Register >> l; + if (l >= max) + return; + Register >> val; +} + diff --git a/ldmicro/lib/freezeLD/freezeLD.h b/ldmicro/lib/freezeLD/freezeLD.h new file mode 100644 index 0000000..f14ef07 --- /dev/null +++ b/ldmicro/lib/freezeLD/freezeLD.h @@ -0,0 +1,52 @@ +/* + * A library for storing parameters in a key file + * + * This library is an analog to the windows freeze library + * developed by Jonathan Westhues. + * + * R Ramana, 2018 + */ + +#ifndef __FREEZE_H +#define __FREEZE_H + +#define LDMICRO_REGISTER "/usr/share/ldmicro" + +#define FREEZE_SUBKEY "LDMicro" + +// #ifndef FREEZE_SUBKEY +// #error must define FREEZE_SUBKEY to a string uniquely identifying the app +// #endif + +#define FreezeWindowPos(hwnd) FreezeWindowPosF(hwnd, FREEZE_SUBKEY, #hwnd) +void FreezeWindowPosF(HWID hWid, char *subKey, char *name); + +#define ThawWindowPos(hwnd) ThawWindowPosF(hwnd, FREEZE_SUBKEY, #hwnd) +void ThawWindowPosF(HWID hWid, char *subKey, char *name); + +#define FreezeDWORD(val) FreezeDWORDF(val, FREEZE_SUBKEY, #val) +void FreezeDWORDF(DWORD val, char *subKey, char *name); + +#define ThawDWORD(val) val = ThawDWORDF(val, FREEZE_SUBKEY, #val) +DWORD ThawDWORDF(DWORD val, char *subKey, char *name); + +#define FreezeString(val) FreezeStringF(val, FREEZE_SUBKEY, #val) +void FreezeStringF(char *val, char *subKey, char *name); + +#define ThawString(val, max) ThawStringF(val, max, FREEZE_SUBKEY, #val) +void ThawStringF(char *val, int max, char *subKey, char *name); + +typedef union regKeyVal{ + int i; + float f; + bool b; + DWORD D; +} KeyVal; + + +typedef struct regKeys{ + char type; + KeyVal val; +} Key; + +#endif diff --git a/ldmicro/lib/linuxUI/CMakeLists.txt b/ldmicro/lib/linuxUI/CMakeLists.txt new file mode 100644 index 0000000..16226dc --- /dev/null +++ b/ldmicro/lib/linuxUI/CMakeLists.txt @@ -0,0 +1,3 @@ +project(LinuxUI) + +add_library(LinuxUI linuxUI.cpp) diff --git a/ldmicro/lib/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h new file mode 100644 index 0000000..9aba23d --- /dev/null +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -0,0 +1,61 @@ +#ifndef __LINUX_LD__ +#define __LINUX_LD__ + +#include "linuxUI.h" + +/// common windows referances for linux + +/// definitions +#define MAX_PATH PATH_MAX +/// CALLBACK or __stdcall os defined empty +#define CALLBACK + +/// typedefs +//typedef int64_t __int64; +typedef bool BOOL; +typedef unsigned char BYTE; +typedef unsigned int DWORD; +typedef long LONG; + +/// all handles will hold a GtkWindow* type +typedef void* PVOID; +typedef GtkWidget* HANDLE; +typedef HANDLE HINSTANCE; +typedef HANDLE HWID; +typedef HANDLE HDC; +typedef HANDLE HMENU; + +typedef GtkWindow* HWND; + +typedef GtkApplication* HAPP; + +/// Check if system is x64 or x86 +#if defined(__UNIX64) +typedef uint64_t UINT_PTR; +#else +typedef unsigned int UINT_PTR; +#endif + +typedef UINT_PTR WPARAM; +typedef unsigned int UINT; + +/// custom classes +class COLORREF : public GdkRGBA{ + public: + COLORREF() + { + this->red = 0.0; + this->green = 0.0; + this->blue = 0.0; + this->alpha = 1.0; + } + COLORREF(int r, int g, int b) + { + this->red = r/255.0; + this->green = g/255.0; + this->blue = b/255.0; + this->alpha = 1.0; + } +}; + +#endif diff --git a/ldmicro/lib/linuxUI/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp new file mode 100644 index 0000000..8237d7d --- /dev/null +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -0,0 +1,18 @@ +#include "linuxUI.h" + +/// Wraper function for gtk_window_has_toplevel_focus +BOOL isFocus(HWID window) +{ + return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(gtk_widget_get_parent_window(GTK_WIDGET(window)))); +} + +COLORREF RGB(int red, int green, int blue) +{ + COLORREF col; + col.red = red/255.0; + col.green = green/255.0; + col.blue = blue/255.0; + col.alpha = 1.0; + + return col; +} \ No newline at end of file diff --git a/ldmicro/lib/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h new file mode 100644 index 0000000..3e49de0 --- /dev/null +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -0,0 +1,19 @@ +#ifndef __LINUX_UI__ +#define __LINUX_UI__ + +/// includes +#include +#include +#include +#include +#include "linuxLD.h" + +/// version control +#define LDMicro_VERSION_MAJOR 1 +#define LDMicro_VERSION_MINOR 0 + +/// functions +BOOL isFocus(HWID); +COLORREF RGB(int, int, int); + +#endif \ No newline at end of file diff --git a/ldmicro/linuxUI.cpp b/ldmicro/linuxUI.cpp deleted file mode 100644 index 854ed09..0000000 --- a/ldmicro/linuxUI.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "linuxUI/linuxUI.h" - -/// Wraper function for gtk_window_has_toplevel_focus -BOOL isFocus(HWND window) -{ - return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(window))); -} - -COLORREF RGB(int red, int green, int blue) -{ - COLORREF col; - col.red = red/255.0; - col.green = green/255.0; - col.blue = blue/255.0; - col.alpha = 1.0; - - return col; -} \ No newline at end of file -- cgit