forked from YggdrasiI/NeoLayoutViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.vala
More file actions
212 lines (172 loc) · 5.8 KB
/
Copy pathmain.vala
File metadata and controls
212 lines (172 loc) · 5.8 KB
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
/* vim: set tabstop=2:softtabstop=2:shiftwidth=2:noexpandtab */
// modules: X
using X;
namespace NeoLayoutViewer{
public ConfigManager configm;
public NeoLayoutViewerApp app;
public NeoWindow neo_win = null;
#if tray
public AppStatusIcon neo_tray = null; //for gnome2.x, kde(?)
#endif
#if indicator
public NeoIndicator neo_indicator = null; //for gnome3.x
#endif
#if _NO_WIN
public KeybindingManager manager = null;
#endif
private void bind_shortcuts() {
manager = new KeybindingManager(neo_win);
var show_shortcut = configm.getConfig().get("show_shortcut").strip();
var move_shortcut = configm.getConfig().get("move_shortcut").strip();
var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip();
if (move_shortcut.length > 0) {
manager.bind(move_shortcut, ()=>{neo_win.numkeypad_move(0);});
}
if (show_shortcut == monitor_shortcut) {
// combination of show + monitor move
debug("Use combined shortcut for window showing and monitor switching.");
manager.bind(monitor_shortcut, ()=>{neo_win.monitor_move(-1, true);});
} else {
if (monitor_shortcut.length > 0) {
manager.bind(monitor_shortcut, ()=>{neo_win.monitor_move();});
}
if (show_shortcut.length > 0) {
manager.bind(show_shortcut, ()=>{neo_win.toggle();});
}
}
}
public static int main(string[] args) {
// Minimal initialization. Check if primary instance and quit otherwise
app = new NeoLayoutViewerApp ();
try {
app.register(); // returns false if and only if throws Error
} catch (Error e) {
debug(@"Gtk.Application.register() failed.\n");
return -1;
}
if (app.is_remote) {
print(@"Application is already running.\n");
// Run without further initalization. It triggers transfer of arguments
// to command_line()-call of primary instance.
app.run(args);
/* Gives D-Bus some time.
* Only needed if app.run() isn't called.
*/
//GLib.Thread.usleep(100000);
return 0;
}
string[] paths = {
GLib.Environment.get_user_config_dir(),
GLib.Environment.get_home_dir(),
GLib.Environment.get_current_dir(),
};
configm = new ConfigManager(paths, "neo_layout_viewer.conf");
// Try to find asset folder (images)
string asset_folder = search_asset_folder( configm.getConfig().get("asset_folder") );
if (asset_folder == null) {
stdout.printf(@"Application start failed because asset folder was not found.\nTry to set path manually in the config file '$(configm.used_config_path)'\n");
stdout.flush();
return 0;
}
// Update asset folder in config
configm.getConfig().set("asset_folder", asset_folder);
debug(@"Asset folder: $(asset_folder)\n");
// Create the window of this application and show it
neo_win = new NeoWindow (configm, app);
#if tray
neo_tray = new AppStatusIcon(neo_win);
#endif
#if indicator
neo_indicator = new NeoIndicator(neo_win);
#endif
#if _NO_WIN
bind_shortcuts();
#endif
app.neo_win = neo_win; // Required for action handlers.
app.add_window(neo_win);
return app.run(args);
}
private static void quit() {
app.quit(); // stops app.run()
}
private static void about_dialog() {
/* This function create the about dialog in
tray menu or indicator menu */
var show_shortcut = configm.getConfig().get("show_shortcut").strip();
var move_shortcut = configm.getConfig().get("move_shortcut").strip();
var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip();
string tmp = "";
if (show_shortcut == monitor_shortcut) {
tmp = "Monitor wechseln/Ausblenden - %s".printf(show_shortcut);
} else {
tmp = """Ein-/Ausblenden - %s
Monitor wechseln - %s""".printf(show_shortcut,
monitor_shortcut);
}
var about = new Gtk.AboutDialog();
about.set_logo(app.neo_win.getIcon());
about.set_destroy_with_parent (true);
about.set_transient_for (app.neo_win);
about.set_version(@"$(RELEASE_VERSION) (git $(GIT_COMMIT_VERSION))");
about.set_program_name("Neo2.0 Ebenenanzeige");
about.set_comments("""Erleichtert das Nachschlagen von Tastenkombinationen im Neo 2.0-Layout.
Olaf Schulz
olaf_schulz+neo@posteo.de
Tastenkombinationen:
%s
Bewegen - %s
Beenden (sofern Fenster selektiert) - q
Verwendete Konfigurationsdatei:
%s""".printf(
tmp,
move_shortcut,
configm.used_config_path)
);
about.set_copyright("LGPLv3");
center_window(about);
about.run();
about.hide();
about.destroy();
}
private void center_window(Gtk.Window win) {
int screen_width = app.neo_win.get_screen_width();
int screen_height = app.neo_win.get_screen_height();
int x, y, w, h;
win.get_size(out w, out h);
x = (screen_width - w) / 2;
y = (screen_height - h) / 2;
win.move(x, y);
}
/* Check given path and shared files folders for the asset folder.
The folder will be assumed as right one if one required file was found.
@return: assed folder or null.
*/
private static string? search_asset_folder(string path) {
string filename = "/icons/Neo-Icon.png"; // Name of file we search for
string[] paths = {
path, // path from config file
"./assets",
"../assets",
SHARED_ASSETS_PATH, // path given by Makefile
};
foreach (var p in paths) {
debug(@"Search assets in $(p)\n");
var file = File.new_for_path (p+filename);
if (file.query_exists(null)) return p;
}
foreach (var s in GLib.Environment.get_system_data_dirs()) {
var env_path = @"$(s)/NeoLayoutViewer/assets";
debug(@"Search assets in $(env_path)\n");
var file2 = File.new_for_path (env_path+filename);
if (file2.query_exists(null)) return env_path;
}
return null;
}
}
#if _NO_WIN
/* Extern C routines */
extern int keysend(uint keysym, int modifiers);
extern int keysend2(uint keysym, uint modsym1, uint modsym2);
extern bool checkCapsLock(X.Display* d);
extern void checkModifier(X.Display* d, int* keycodes, int nkeycodes, int* pressed );
#endif