summaryrefslogtreecommitdiff
path: root/common/linux/freeze.cpp
diff options
context:
space:
mode:
authorRr422018-05-27 19:21:59 +0530
committerRr422018-05-27 19:21:59 +0530
commit4be201f18c265a0bd66b2500ccdb383e91a436bd (patch)
tree6957fd4cf6f9f46f1c5ae2d753b914fbf61b1f7f /common/linux/freeze.cpp
parenta2e0c92b2f4edfd067f8671dab18c92835143528 (diff)
downloadLDMicroGtk-4be201f18c265a0bd66b2500ccdb383e91a436bd.tar.gz
LDMicroGtk-4be201f18c265a0bd66b2500ccdb383e91a436bd.tar.bz2
LDMicroGtk-4be201f18c265a0bd66b2500ccdb383e91a436bd.zip
Updated freeze library to add an entry to register file
Diffstat (limited to 'common/linux/freeze.cpp')
-rw-r--r--common/linux/freeze.cpp408
1 files changed, 212 insertions, 196 deletions
diff --git a/common/linux/freeze.cpp b/common/linux/freeze.cpp
index 01724a6..0d27ca7 100644
--- a/common/linux/freeze.cpp
+++ b/common/linux/freeze.cpp
@@ -8,205 +8,221 @@
*/
#include "freeze.h"
#include <linuxUI/linuxUI.h>
+#include <cstdlib>
+#include <fstream>
#include <stdlib.h>
#include <stdio.h>
-// /*
-// * 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)
-// {
-// RECT r;
-// GetWindowRect(hwnd, &r);
-
-// HKEY software;
-// if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS)
-// return;
-
-// char *keyName = (char *)malloc(strlen(name) + 30);
-// if(!keyName)
-// return;
-
-// HKEY sub;
-// if(RegCreateKeyEx(software, subKey, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &sub, NULL) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_left", name);
-// if(RegSetValueEx(sub, keyName, 0, REG_DWORD, (BYTE *)&(r.left), sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_right", name);
-// if(RegSetValueEx(sub, keyName, 0, REG_DWORD, (BYTE *)&(r.right), sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_top", name);
-// if(RegSetValueEx(sub, keyName, 0, REG_DWORD, (BYTE *)&(r.top), sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_bottom", name);
-// if(RegSetValueEx(sub, keyName, 0, REG_DWORD, (BYTE *)&(r.bottom), sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_maximized", name);
-// DWORD v = IsZoomed(hwnd);
-// if(RegSetValueEx(sub, keyName, 0, REG_DWORD, (BYTE *)&(v), sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-
-// 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)
-// {
-// HKEY software;
-// if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS)
-// return;
-
-// HKEY sub;
-// if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
-// return;
-
-// char *keyName = (char *)malloc(strlen(name) + 30);
-// if(!keyName)
-// return;
-
-// DWORD l;
-// RECT r;
-
-// sprintf(keyName, "%s_left", name);
-// l = sizeof(DWORD);
-// if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.left), &l) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_right", name);
-// l = sizeof(DWORD);
-// if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.right), &l) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_top", name);
-// l = sizeof(DWORD);
-// if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.top), &l) != ERROR_SUCCESS)
-// return;
-
-// sprintf(keyName, "%s_bottom", name);
-// l = sizeof(DWORD);
-// if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.bottom), &l) != ERROR_SUCCESS)
-// return;
-
-// 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);
-
-// free(keyName);
-// }
-
-// /*
-// * store a DWORD setting in the registry
-// */
-// 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)
-// return;
+/*
+ * 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)
+{
+ if (-1 == system("mkdir -p /usr/share/ldmicro"))
+ return;
+
+ std::ofstream Register("binConf", std::ios::binary | std::ios::trunc);
+ if (!Register.is_open())
+ return;
+
+ char *keyName = (char *)malloc(strlen(name) + 30);
+ if(!keyName)
+ return;
+
+ Key newkey;
+
+ int val;
+
+ sprintf(keyName, "%s_width", name);
+ gtk_window_get_size(GTK_WINDOW(hwnd), &val, NULL);
+ newKey.name = keyName;
+ newKey.type = 'i';
+ newKey.val = val;
+ Register.write((char*) &newKey, sizeof(newKey));
+
+ sprintf(keyName, "%s_height", name);
+ gtk_window_get_size(GTK_WINDOW(hwnd), NULL, &val);
+ newKey.name = keyName;
+ newKey.type = 'i';
+ newKey.val = val;
+ Register.write((char*) &newKey, sizeof(newKey));
+
+
+ sprintf(keyName, "%s_posX", name);
+ gtk_window_get_position(GTK_WINDOW(hwnd), &val, NULL);
+ newKey.name = keyName;
+ newKey.type = 'i';
+ newKey.val = val;
+ Register.write((char*) &newKey, sizeof(newKey));
+
+ sprintf(keyName, "%s_posY", name);
+ gtk_window_get_position(GTK_WINDOW(hwnd), NULL, &val);
+ newKey.name = keyName;
+ newKey.type = 'i';
+ newKey.val = val;
+ Register.write((char*) &newKey, sizeof(newKey));
+
+ sprintf(keyName, "%s_maximized", name);
+ newKey.name = keyName;
+ newKey.type = 'b';
+ newKey.val = gtk_window_is_maximized(GTK_WINDOW(hwnd));
+ Register.write((char*) &newKey, sizeof(newKey));
+
+ 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)
+{
+ HKEY software;
+ if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS)
+ return;
+
+ HKEY sub;
+ if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
+ return;
+
+ char *keyName = (char *)malloc(strlen(name) + 30);
+ if(!keyName)
+ return;
+
+ DWORD l;
+ RECT r;
+
+ sprintf(keyName, "%s_left", name);
+ l = sizeof(DWORD);
+ if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.left), &l) != ERROR_SUCCESS)
+ return;
+
+ sprintf(keyName, "%s_right", name);
+ l = sizeof(DWORD);
+ if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.right), &l) != ERROR_SUCCESS)
+ return;
+
+ sprintf(keyName, "%s_top", name);
+ l = sizeof(DWORD);
+ if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.top), &l) != ERROR_SUCCESS)
+ return;
+
+ sprintf(keyName, "%s_bottom", name);
+ l = sizeof(DWORD);
+ if(RegQueryValueEx(sub, keyName, NULL, NULL, (BYTE *)&(r.bottom), &l) != ERROR_SUCCESS)
+ return;
+
+ 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);
+
+ free(keyName);
+}
+
+/*
+ * store a DWORD setting in the registry
+ */
+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)
+ return;
-// if(RegSetValueEx(sub, name, 0, REG_DWORD, (BYTE *)&val, sizeof(DWORD)) != ERROR_SUCCESS)
-// return;
-// }
-
-// /*
-// * retrieve a DWORD setting, or return the default if that setting is unavailable
-// */
-// DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
-// {
-// HKEY software;
-// if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS)
-// return val;
-
-// HKEY sub;
-// if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
-// return val;
-
-// DWORD l = sizeof(DWORD);
-// DWORD v;
-// if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)&v, &l) != ERROR_SUCCESS)
-// return val;
-
-// return v;
-// }
-
-// /*
-// * store a string setting in the registry
-// */
-// 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_DWORD, (BYTE *)&val, sizeof(DWORD)) != ERROR_SUCCESS)
+ return;
+}
+
+/*
+ * retrieve a DWORD setting, or return the default if that setting is unavailable
+ */
+DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
+{
+ HKEY software;
+ if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software) != ERROR_SUCCESS)
+ return val;
+
+ HKEY sub;
+ if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
+ return val;
+
+ DWORD l = sizeof(DWORD);
+ DWORD v;
+ if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)&v, &l) != ERROR_SUCCESS)
+ return val;
+
+ return v;
+}
+
+/*
+ * store a string setting in the registry
+ */
+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;
-// }
-
-// /*
-// * retrieve a string setting, or return the default if that setting is unavailable
-// */
-// 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)
-// return;
-
-// HKEY sub;
-// if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
-// return;
-
-// DWORD l = max;
-// if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)val, &l) != ERROR_SUCCESS)
-// return;
-// if(l >= (DWORD)max) return;
-
-// val[l] = '\0';
-// return;
-// }
+ if(RegSetValueEx(sub, name, 0, REG_SZ, (BYTE *)val, strlen(val)+1) != ERROR_SUCCESS)
+ return;
+}
+
+/*
+ * retrieve a string setting, or return the default if that setting is unavailable
+ */
+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)
+ return;
+
+ HKEY sub;
+ if(RegOpenKeyEx(software, subKey, 0, KEY_ALL_ACCESS, &sub) != ERROR_SUCCESS)
+ return;
+
+ DWORD l = max;
+ if(RegQueryValueEx(sub, name, NULL, NULL, (BYTE *)val, &l) != ERROR_SUCCESS)
+ return;
+ if(l >= (DWORD)max) return;
+
+ val[l] = '\0';
+ return;
+}