1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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;
}
|