diff options
author | Rr42 | 2018-05-29 10:46:19 +0530 |
---|---|---|
committer | Rr42 | 2018-05-29 10:46:19 +0530 |
commit | 5c01aef5fd87870b63511f17bd50405a0df08a3b (patch) | |
tree | fd24160ed213c2a37ea6c8ea6e816fcfed984628 /ldmicro | |
parent | 08e70fc82ebfae4cc11ad6eee0dc3197b1d1672b (diff) | |
download | LDMicroGtk-5c01aef5fd87870b63511f17bd50405a0df08a3b.tar.gz LDMicroGtk-5c01aef5fd87870b63511f17bd50405a0df08a3b.tar.bz2 LDMicroGtk-5c01aef5fd87870b63511f17bd50405a0df08a3b.zip |
Freeze library updated and renamed to freezeLD (working)
Diffstat (limited to 'ldmicro')
-rw-r--r-- | ldmicro/CMakeLists.txt | 81 | ||||
-rw-r--r-- | ldmicro/draw_outputdev.cpp | 2 | ||||
-rw-r--r-- | ldmicro/ldmicro.cpp | 4 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/CMakeLists.txt | 4 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/freezeLD.cpp | 265 | ||||
-rw-r--r-- | ldmicro/lib/freezeLD/freezeLD.h | 52 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/CMakeLists.txt | 3 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxLD.h (renamed from ldmicro/includes/linuxUI/linuxLD.h) | 3 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.cpp (renamed from ldmicro/linuxUI.cpp) | 6 | ||||
-rw-r--r-- | ldmicro/lib/linuxUI/linuxUI.h (renamed from ldmicro/includes/linuxUI/linuxUI.h) | 4 |
10 files changed, 377 insertions, 47 deletions
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 <stdio.h> #include <stdlib.h> 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 <stdio.h> #include <stdlib.h> @@ -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 <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(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/includes/linuxUI/linuxLD.h b/ldmicro/lib/linuxUI/linuxLD.h index 53194e1..9aba23d 100644 --- a/ldmicro/includes/linuxUI/linuxLD.h +++ b/ldmicro/lib/linuxUI/linuxLD.h @@ -1,7 +1,7 @@ #ifndef __LINUX_LD__ #define __LINUX_LD__ -#include "linuxUI/linuxUI.h" +#include "linuxUI.h" /// common windows referances for linux @@ -15,6 +15,7 @@ typedef bool BOOL; typedef unsigned char BYTE; typedef unsigned int DWORD; +typedef long LONG; /// all handles will hold a GtkWindow* type typedef void* PVOID; diff --git a/ldmicro/linuxUI.cpp b/ldmicro/lib/linuxUI/linuxUI.cpp index 854ed09..8237d7d 100644 --- a/ldmicro/linuxUI.cpp +++ b/ldmicro/lib/linuxUI/linuxUI.cpp @@ -1,9 +1,9 @@ -#include "linuxUI/linuxUI.h" +#include "linuxUI.h" /// Wraper function for gtk_window_has_toplevel_focus -BOOL isFocus(HWND window) +BOOL isFocus(HWID window) { - return (BOOL) gtk_window_has_toplevel_focus(GTK_WINDOW(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) diff --git a/ldmicro/includes/linuxUI/linuxUI.h b/ldmicro/lib/linuxUI/linuxUI.h index 01b7af2..3e49de0 100644 --- a/ldmicro/includes/linuxUI/linuxUI.h +++ b/ldmicro/lib/linuxUI/linuxUI.h @@ -6,14 +6,14 @@ #include <linux/limits.h> #include <stdio.h> #include <inttypes.h> -#include "linuxUI/linuxLD.h" +#include "linuxLD.h" /// version control #define LDMicro_VERSION_MAJOR 1 #define LDMicro_VERSION_MINOR 0 /// functions -BOOL isFocus(HWND); +BOOL isFocus(HWID); COLORREF RGB(int, int, int); #endif
\ No newline at end of file |