Normalize code syntax

This commit is contained in:
Olaf Schulz 2019-11-12 16:10:04 +01:00
parent 5c468bf2b1
commit c7d3cb0ca8
7 changed files with 108 additions and 106 deletions

View File

@ -31,7 +31,7 @@ namespace NeoLayoutViewer{
} }
protected override void activate () { protected override void activate () {
if (this.neo_win == null ) { if (this.neo_win == null) {
// Create the window of this application and show it // Create the window of this application and show it
this.neo_win = new NeoWindow (this); this.neo_win = new NeoWindow (this);
@ -48,32 +48,32 @@ namespace NeoLayoutViewer{
#endif #endif
this.add_window(this.neo_win); this.add_window(this.neo_win);
}else{ } else {
// reached if app.activate() called by remote instance // reached if app.activate() called by remote instance
this.neo_win.toggle(); this.neo_win.toggle();
} }
} }
private void bind_shortcuts(){ private void bind_shortcuts() {
manager = new KeybindingManager(this.neo_win); manager = new KeybindingManager(this.neo_win);
var show_shortcut = configm.getConfig().get("show_shortcut").strip(); var show_shortcut = configm.getConfig().get("show_shortcut").strip();
var move_shortcut = configm.getConfig().get("move_shortcut").strip(); var move_shortcut = configm.getConfig().get("move_shortcut").strip();
var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip(); var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip();
if (move_shortcut.length > 0){ if (move_shortcut.length > 0) {
manager.bind(move_shortcut, ()=>{this.neo_win.numkeypad_move(0);}); manager.bind(move_shortcut, ()=>{this.neo_win.numkeypad_move(0);});
} }
if (show_shortcut == monitor_shortcut){ if (show_shortcut == monitor_shortcut) {
// combination of show + monitor move // combination of show + monitor move
debug("Use combined shortcut for window showing and monitor switching."); debug("Use combined shortcut for window showing and monitor switching.");
manager.bind(monitor_shortcut, ()=>{this.neo_win.monitor_move(-1, true);}); manager.bind(monitor_shortcut, ()=>{this.neo_win.monitor_move(-1, true);});
}else{ } else {
if (monitor_shortcut.length > 0){ if (monitor_shortcut.length > 0) {
manager.bind(monitor_shortcut, ()=>{this.neo_win.monitor_move();}); manager.bind(monitor_shortcut, ()=>{this.neo_win.monitor_move();});
} }
if (show_shortcut.length > 0){ if (show_shortcut.length > 0) {
manager.bind(show_shortcut, ()=>{this.neo_win.toggle();}); manager.bind(show_shortcut, ()=>{this.neo_win.toggle();});
} }
} }

View File

@ -20,10 +20,10 @@ namespace NeoLayoutViewer {
string conffile2 = null; string conffile2 = null;
//1. Try to read conf file //1. Try to read conf file
foreach( var path in paths ){ foreach (var path in paths) {
string testfile = @"$(path)/$(conffile)"; string testfile = @"$(path)/$(conffile)";
debug(@"Search $(testfile)\n"); debug(@"Search $(testfile)\n");
if( search_config_file(testfile) ){ if (search_config_file(testfile)) {
conffile2 = testfile; conffile2 = testfile;
debug(@"Found $(testfile)\n"); debug(@"Found $(testfile)\n");
break; break;
@ -31,11 +31,11 @@ namespace NeoLayoutViewer {
} }
//2. Try deprecated name with leading dot //2. Try deprecated name with leading dot
if( conffile2 == null ){ if (conffile2 == null) {
foreach( var path in paths ){ foreach (var path in paths) {
string testfile = @"$(path)/.$(conffile)"; string testfile = @"$(path)/.$(conffile)";
debug(@"Search $(testfile)\n"); debug(@"Search $(testfile)\n");
if( search_config_file(testfile) ){ if (search_config_file(testfile)) {
conffile2 = testfile; conffile2 = testfile;
debug(@"Found $(testfile)\n"); debug(@"Found $(testfile)\n");
break; break;
@ -44,10 +44,10 @@ namespace NeoLayoutViewer {
} }
//3. Try to write new conf file if read had failed //3. Try to write new conf file if read had failed
if( conffile2 == null ){ if (conffile2 == null) {
foreach( var path in paths ){ foreach (var path in paths) {
string testfile = @"$(path)/$(conffile)"; string testfile = @"$(path)/$(conffile)";
if( create_conf_file(testfile) > -1){ if (create_conf_file(testfile) > -1) {
debug(@"Create $(testfile)\n"); debug(@"Create $(testfile)\n");
conffile2 = testfile; conffile2 = testfile;
break; break;
@ -57,7 +57,7 @@ namespace NeoLayoutViewer {
debug(@"Config file: $(conffile2)"); debug(@"Config file: $(conffile2)");
if(search_config_file(conffile2)) if (search_config_file(conffile2))
load_config_file(conffile2); load_config_file(conffile2);
add_intern_values(); add_intern_values();
@ -80,7 +80,7 @@ namespace NeoLayoutViewer {
Standard values. This vaules will be written in the config file Standard values. This vaules will be written in the config file
if it was not found. if it was not found.
*/ */
public void add_defaults(){ public void add_defaults() {
//config.set("show_shortcut", "<Mod4><Super_L>n", "Toggle the visibility of the window."); //config.set("show_shortcut", "<Mod4><Super_L>n", "Toggle the visibility of the window.");
addSetting("show_shortcut", "<Ctrl><Alt>q", "Toggle the visibility of the window."); addSetting("show_shortcut", "<Ctrl><Alt>q", "Toggle the visibility of the window.");
addSetting("on_top", "1", "Show window on top."); addSetting("on_top", "1", "Show window on top.");
@ -161,8 +161,8 @@ namespace NeoLayoutViewer {
data_stream.put_string(e.key + " = " + e.value + "\n"); data_stream.put_string(e.key + " = " + e.value + "\n");
} }
} // Streams } // Streams
catch ( GLib.IOError e){ return -1; } catch ( GLib.IOError e) { return -1; }
catch ( GLib.Error e){ return -1; } catch ( GLib.Error e) { return -1; }
return 0; return 0;
} }
@ -187,7 +187,7 @@ namespace NeoLayoutViewer {
if (comment.match(line)) continue; if (comment.match(line)) continue;
split = regex.split(line); split = regex.split(line);
if(split.length>1){ if (split.length>1) {
this.config.set(split[0].strip(), split[1].strip()); this.config.set(split[0].strip(), split[1].strip());
} }
} }

View File

@ -45,7 +45,7 @@ namespace NeoLayoutViewer {
this.winMain.check_resize.connect(main_resized); this.winMain.check_resize.connect(main_resized);
} }
private void main_resized(){ private void main_resized() {
int width; int width;
int height; int height;
@ -53,13 +53,13 @@ namespace NeoLayoutViewer {
//height = this.winMain.get_allocated_height(); //height = this.winMain.get_allocated_height();
this.winMain.get_size(out width, out height); this.winMain.get_size(out width, out height);
if( this._width == width && this._height == height ){ if (this._width == width && this._height == height) {
return; // to avoid infinite resize live lock... return; // to avoid infinite resize live lock...
} }
debug(@"Window resize signal. New width/height: $(width)/$(height)"); debug(@"Window resize signal. New width/height: $(width)/$(height)");
if( width == 1 && height == 1){ if (width == 1 && height == 1) {
return; // (1,1) send if user show/hides window very fast. return; // (1, 1) send if user show/hides window very fast.
} }
this._width = width; this._width = width;
@ -132,7 +132,7 @@ namespace NeoLayoutViewer {
gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 96, false, 0); gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 96, false, 0);
//free space //free space
gridCell(22.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, -1, false, -1); gridCell(22.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, -1, false, -1);
// print,scroll,break // print, scroll, break
gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 107, false, 0); gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 107, false, 0);
gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 78, false, 0); gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 78, false, 0);
gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 127, true, 0); gridCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, 127, true, 0);
@ -367,7 +367,7 @@ namespace NeoLayoutViewer {
int y = 0; int y = 0;
// detach cells from grid // detach cells from grid
/*foreach (KeyEventCell w in this.eventCells.values){ /*foreach (KeyEventCell w in this.eventCells.values) {
this.remove(w); this.remove(w);
}*/ }*/
// Reset id. Number will increased in ever moveCell call // Reset id. Number will increased in ever moveCell call
@ -407,7 +407,7 @@ namespace NeoLayoutViewer {
moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false); moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false);
//free space //free space
moveCell(22.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false); moveCell(22.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false);
// print,scroll,break // print, scroll, break
moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false); moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false);
moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false); moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, false);
moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, true); moveCell(44.0, 30.0, ref x_unscaled, ref y_unscaled, ref x, ref y, scaleX, scaleY, true);
@ -645,19 +645,19 @@ namespace NeoLayoutViewer {
int width; int width;
int height; int height;
if( x_unscaled + width_unscaled > win_width_unscaled){ if (x_unscaled + width_unscaled > win_width_unscaled) {
debug(@"AAAA cell too wide! Change from $(width_unscaled) to $(win_width_unscaled-x_unscaled)"); debug(@"AAAA cell too wide! Change from $(width_unscaled) to $(win_width_unscaled-x_unscaled)");
width_unscaled = win_width_unscaled - x_unscaled; width_unscaled = win_width_unscaled - x_unscaled;
width = win_width - x; width = win_width - x;
}else{ } else {
width = (int)GLib.Math.floor((x_unscaled + width_unscaled) * scaleX - x ); width = (int)GLib.Math.floor((x_unscaled + width_unscaled) * scaleX - x );
} }
if( y_unscaled + height_unscaled > win_height_unscaled){ if (y_unscaled + height_unscaled > win_height_unscaled) {
debug(@"AAAA cell too tall! Change from $(height_unscaled) to $(win_height_unscaled-y_unscaled)"); debug(@"AAAA cell too tall! Change from $(height_unscaled) to $(win_height_unscaled-y_unscaled)");
height_unscaled = win_height_unscaled - y_unscaled; height_unscaled = win_height_unscaled - y_unscaled;
height = win_height - y; height = win_height - y;
}else{ } else {
height = (int)GLib.Math.floor((y_unscaled + height_unscaled) * scaleY - y ); height = (int)GLib.Math.floor((y_unscaled + height_unscaled) * scaleY - y );
} }
*/ */
@ -675,7 +675,7 @@ namespace NeoLayoutViewer {
// Modifier, die andere Buchstabenebenen aktivieren. Zusätzlich Ebenen-Bild einblenden. // Modifier, die andere Buchstabenebenen aktivieren. Zusätzlich Ebenen-Bild einblenden.
cell = new KeyEventCell.modifier(winMain, width, height, width, height, keycode /*=modifier array index*/ ); cell = new KeyEventCell.modifier(winMain, width, height, width, height, keycode /*=modifier array index*/ );
break; break;
//Andere Modifier (CTRL, Alt,... ) //Andere Modifier (CTRL, Alt, ... )
case 2: //left ctrl case 2: //left ctrl
//cell = new KeyEventCell.modifier(winMain, width, height, width, height, keycode ); //cell = new KeyEventCell.modifier(winMain, width, height, width, height, keycode );
cell = new KeyEventCell.modifier2(winMain, width, height, width, height, keycode /*modifier array index */, "tastatur_ctrl_left_2.png" ); cell = new KeyEventCell.modifier2(winMain, width, height, width, height, keycode /*modifier array index */, "tastatur_ctrl_left_2.png" );
@ -724,7 +724,7 @@ namespace NeoLayoutViewer {
} }
// TODO // TODO
if (this.color_event_boxes && cell.get_children().length() == 0){ if (this.color_event_boxes && cell.get_children().length() == 0) {
Label l = new Label(""); // do not use non-empty string Label l = new Label(""); // do not use non-empty string
l.show(); l.show();
@ -760,19 +760,19 @@ namespace NeoLayoutViewer {
int width; int width;
int height; int height;
if( x_unscaled + width_unscaled > win_width_unscaled){ if (x_unscaled + width_unscaled > win_width_unscaled) {
debug(@"AAAA cell too wide! Change from $(width_unscaled) to $(win_width_unscaled-x_unscaled)"); debug(@"AAAA cell too wide! Change from $(width_unscaled) to $(win_width_unscaled-x_unscaled)");
width_unscaled = win_width_unscaled - x_unscaled; width_unscaled = win_width_unscaled - x_unscaled;
width = win_width - x; width = win_width - x;
}else{ } else {
width = (int)GLib.Math.floor((x_unscaled + width_unscaled) * scaleX - x ); width = (int)GLib.Math.floor((x_unscaled + width_unscaled) * scaleX - x );
} }
if( y_unscaled + height_unscaled > win_height_unscaled){ if (y_unscaled + height_unscaled > win_height_unscaled) {
debug(@"AAAA cell too tall! Change from $(height_unscaled) to $(win_height_unscaled-y_unscaled)"); debug(@"AAAA cell too tall! Change from $(height_unscaled) to $(win_height_unscaled-y_unscaled)");
height_unscaled = win_height_unscaled - y_unscaled; height_unscaled = win_height_unscaled - y_unscaled;
height = win_height - y; height = win_height - y;
}else{ } else {
height = (int)GLib.Math.floor((y_unscaled + height_unscaled) * scaleY - y ); height = (int)GLib.Math.floor((y_unscaled + height_unscaled) * scaleY - y );
} }
*/ */
@ -822,7 +822,7 @@ namespace NeoLayoutViewer {
Achtung, mittlerweile ist es die Identitätsabbildung, da die zwei Achtung, mittlerweile ist es die Identitätsabbildung, da die zwei
redundanten Layer, die durch Caps-Lock entstehen, entfernt wurden. redundanten Layer, die durch Caps-Lock entstehen, entfernt wurden.
*/ */
private const short[] layer_permutation = {0,1,2,3,5,4,6}; private const short[] layer_permutation = {0, 1, 2, 3, 5, 4, 6};
private KeyEventCell.all(NeoWindow winMain, double unscaled_width, double unscaled_height, int width, int height) { private KeyEventCell.all(NeoWindow winMain, double unscaled_width, double unscaled_height, int width, int height) {
this.winMain = winMain; this.winMain = winMain;
@ -844,21 +844,21 @@ namespace NeoLayoutViewer {
this.keysym = keysym; this.keysym = keysym;
this.button_press_event.connect ((event) => { this.button_press_event.connect ((event) => {
if (event.button != 1){ if (event.button != 1) {
return false; return false;
} }
uint ks = this.keysym[NeoLayoutViewer.KeyEventCell.layer_permutation[winMain.layer] - 1]; uint ks = this.keysym[NeoLayoutViewer.KeyEventCell.layer_permutation[winMain.layer] - 1];
int modi = winMain.getActiveModifierMask({4,5}); //ctrl+alt mask int modi = winMain.getActiveModifierMask({4, 5}); //ctrl+alt mask
if (ks < 1) return false; if (ks < 1) return false;
#if _NO_WIN #if _NO_WIN
if (modi == 0 || true) { if (modi == 0 || true) {
// Alt-Mask do not work :-( // Alt-Mask do not work :-(
keysend(ks,modi); keysend(ks, modi);
} else { } else {
//debug("Variante mit zweitem Modifier."); //debug("Variante mit zweitem Modifier.");
keysend2(ks,modi & Gdk.ModifierType.CONTROL_MASK, modi & Gdk.ModifierType.MOD1_MASK); keysend2(ks, modi & Gdk.ModifierType.CONTROL_MASK, modi & Gdk.ModifierType.MOD1_MASK);
} }
#endif #endif
//GLib.stdout.printf(@"Key: $(ks)\n"); GLib.stdout.flush(); //GLib.stdout.printf(@"Key: $(ks)\n"); GLib.stdout.flush();
@ -885,7 +885,7 @@ namespace NeoLayoutViewer {
}); });
} }
public KeyEventCell.modifier2(NeoWindow winMain, double unscaled_width, double unscaled_height, int width, int height, int modifier_index, string pressed_key_image ){ public KeyEventCell.modifier2(NeoWindow winMain, double unscaled_width, double unscaled_height, int width, int height, int modifier_index, string pressed_key_image) {
this.all(winMain, unscaled_width, unscaled_height, width, height); this.all(winMain, unscaled_width, unscaled_height, width, height);
this.modifier_index = modifier_index; this.modifier_index = modifier_index;
this.image_source_id = @"modifier_$(pressed_key_image)"; this.image_source_id = @"modifier_$(pressed_key_image)";
@ -902,7 +902,7 @@ namespace NeoLayoutViewer {
// store unscaled variant (TODO: redundant) // store unscaled variant (TODO: redundant)
winMain.image_buffer.set(this.image_source_id, modifier_pixbufs[0]); winMain.image_buffer.set(this.image_source_id, modifier_pixbufs[0]);
}else{ } else {
modifier_pixbufs = { modifier_pixbufs = {
winMain.image_buffer.get(this.image_source_id) winMain.image_buffer.get(this.image_source_id)
}; };
@ -952,11 +952,11 @@ namespace NeoLayoutViewer {
* that Gtk+ will actually give this size to the widget. * that Gtk+ will actually give this size to the widget.
*/ */
public override void get_preferred_width(out int minimum_width, out int natural_width){ public override void get_preferred_width(out int minimum_width, out int natural_width) {
minimum_width = width; minimum_width = width;
natural_width = width; natural_width = width;
} }
public override void get_preferred_height(out int minimum_height, out int natural_height){ public override void get_preferred_height(out int minimum_height, out int natural_height) {
minimum_height = height; minimum_height = height;
natural_height = height; natural_height = height;
} }
@ -966,12 +966,12 @@ namespace NeoLayoutViewer {
// Wrapper to store array into hash map?! // Wrapper to store array into hash map?!
public class KeycodeArray { public class KeycodeArray {
public uint[] val; public uint[] val;
public KeycodeArray(uint[] val){ public KeycodeArray(uint[] val) {
this.val = val; this.val = val;
} }
} }
public Gee.HashMap<int, KeycodeArray> generateKeysyms(){ public Gee.HashMap<int, KeycodeArray> generateKeysyms() {
Gee.HashMap<int, KeycodeArray> keysyms = new Gee.HashMap<int, KeycodeArray>(); Gee.HashMap<int, KeycodeArray> keysyms = new Gee.HashMap<int, KeycodeArray>();
/* Define keyboard layout. this object maps the keycodes to the list of keycodes of each keyboard layer. */ /* Define keyboard layout. this object maps the keycodes to the list of keycodes of each keyboard layer. */

View File

@ -177,7 +177,7 @@ namespace NeoLayoutViewer {
if (xevent->type == X.EventType.KeyPress) { if (xevent->type == X.EventType.KeyPress) {
foreach(Keybinding binding in bindings) { foreach (Keybinding binding in bindings) {
// remove NumLock, CapsLock and ScrollLock from key state // remove NumLock, CapsLock and ScrollLock from key state
uint event_mods = xevent.xkey.state & ~ (lock_modifiers[7]); uint event_mods = xevent.xkey.state & ~ (lock_modifiers[7]);
@ -194,7 +194,7 @@ namespace NeoLayoutViewer {
/* /*
Checks periodically which modifier are pressed. Checks periodically which modifier are pressed.
*/ */
private bool modifier_timer(){ private bool modifier_timer() {
unowned X.Display display = Gdk.X11.get_default_xdisplay(); unowned X.Display display = Gdk.X11.get_default_xdisplay();
checkModifier(display, &modifier_keycodes[0], modifier_keycodes.length, &modifier_pressed[0]); checkModifier(display, &modifier_keycodes[0], modifier_keycodes.length, &modifier_pressed[0]);

View File

@ -20,7 +20,7 @@ namespace NeoLayoutViewer{
// Try to find asset folder (images) // Try to find asset folder (images)
string asset_folder = search_asset_folder( configm.getConfig().get("asset_folder") ); string asset_folder = search_asset_folder( configm.getConfig().get("asset_folder") );
if( asset_folder == null ){ 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.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(); stdout.flush();
return 0; return 0;
@ -42,7 +42,7 @@ namespace NeoLayoutViewer{
if (app.is_remote) { if (app.is_remote) {
print(@"Application is already running.\n"); print(@"Application is already running.\n");
app.activate(); app.activate();
}else{ } else {
return app.run(args); return app.run(args);
} }
@ -62,9 +62,9 @@ namespace NeoLayoutViewer{
var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip(); var monitor_shortcut = configm.getConfig().get("monitor_shortcut").strip();
string tmp = ""; string tmp = "";
if (show_shortcut == monitor_shortcut && false){ if (show_shortcut == monitor_shortcut && false) {
tmp = "Monitor wechseln/Ausblenden - %s".printf(show_shortcut); tmp = "Monitor wechseln/Ausblenden - %s".printf(show_shortcut);
}else{ } else {
tmp = """Ein-/Ausblenden - %s tmp = """Ein-/Ausblenden - %s
Monitor wechseln - %s""".printf(show_shortcut, Monitor wechseln - %s""".printf(show_shortcut,
monitor_shortcut); monitor_shortcut);
@ -100,7 +100,7 @@ namespace NeoLayoutViewer{
} }
private void center_window(Gtk.Window win){ private void center_window(Gtk.Window win) {
int screen_width = app.neo_win.get_screen_width(); int screen_width = app.neo_win.get_screen_width();
int screen_height = app.neo_win.get_screen_height(); int screen_height = app.neo_win.get_screen_height();
int x, y, w, h; int x, y, w, h;
@ -114,7 +114,7 @@ namespace NeoLayoutViewer{
The folder will be assumed as right one if one required file was found. The folder will be assumed as right one if one required file was found.
@return: assed folder or null. @return: assed folder or null.
*/ */
private static string? search_asset_folder(string path){ private static string? search_asset_folder(string path) {
/*const*/ string filename = "/icons/Neo-Icon.png"; /*const*/ string filename = "/icons/Neo-Icon.png";
string[] paths = { string[] paths = {
@ -124,17 +124,17 @@ namespace NeoLayoutViewer{
SHARED_ASSETS_PATH, // path given by Makefile SHARED_ASSETS_PATH, // path given by Makefile
}; };
foreach( var p in paths ){ foreach (var p in paths) {
debug(@"Search assets in $(p)\n"); debug(@"Search assets in $(p)\n");
var file = File.new_for_path (p+filename); var file = File.new_for_path (p+filename);
if( file.query_exists(null)) return p; if (file.query_exists(null)) return p;
} }
foreach( var s in GLib.Environment.get_system_data_dirs()){ foreach (var s in GLib.Environment.get_system_data_dirs()) {
var env_path = @"$(s)/NeoLayoutViewer/assets"; var env_path = @"$(s)/NeoLayoutViewer/assets";
debug(@"Search assets in $(env_path)\n"); debug(@"Search assets in $(env_path)\n");
var file2 = File.new_for_path (env_path+filename); var file2 = File.new_for_path (env_path+filename);
if( file2.query_exists(null)) return env_path; if (file2.query_exists(null)) return env_path;
} }
return null; return null;

View File

@ -29,7 +29,7 @@ namespace NeoLayoutViewer {
this.active = new_state; this.active = new_state;
if (this.active == 0) { if (this.active == 0) {
modKeyImage.hide(); modKeyImage.hide();
}else{ } else {
modKeyImage.show(); modKeyImage.show();
} }
} }
@ -55,7 +55,7 @@ namespace NeoLayoutViewer {
private int _layer = 1; private int _layer = 1;
public int layer { public int layer {
get { return _layer; } get { return _layer; }
set { if (value < 1 || value > 6) { _layer = 1; }else{ _layer = value; } } set { if (value < 1 || value > 6) { _layer = 1; } else { _layer = value; } }
} }
public int[] active_modifier_by_keyboard; public int[] active_modifier_by_keyboard;
public int[] active_modifier_by_mouse; public int[] active_modifier_by_mouse;
@ -190,7 +190,7 @@ namespace NeoLayoutViewer {
// Valid range: [1, 10*number_of_monitors - 1] // Valid range: [1, 10*number_of_monitors - 1]
position_cycle[j] = int.max(int.min(int.parse(split[i]), position_cycle.length-1), 1); position_cycle[j] = int.max(int.min(int.parse(split[i]), position_cycle.length-1), 1);
if ( position_cycle[j] == 0 ){ if (position_cycle[j] == 0) {
// Invalid number parsed (or parsing failed). Print error message and use predefined array // Invalid number parsed (or parsing failed). Print error message and use predefined array
GLib.stdout.printf("Position cycle reading failed. Problematic value: $(split[i])\n"); GLib.stdout.printf("Position cycle reading failed. Problematic value: $(split[i])\n");
throw new PositionArrayParsingError.CODE_1A("Unexpected Integer"); throw new PositionArrayParsingError.CODE_1A("Unexpected Integer");
@ -198,18 +198,20 @@ namespace NeoLayoutViewer {
GLib.assert( position_cycle[j] > 0 ); GLib.assert( position_cycle[j] > 0 );
j++; j++;
if (j%10 == 0){ j++; } if (j%10 == 0) { j++; }
} }
} catch (PositionArrayParsingError e) { } catch (PositionArrayParsingError e) {
fill_position_cycle_default(ref position_cycle); fill_position_cycle_default(ref position_cycle);
} catch (RegexError e) { } catch (RegexError e) {
fill_position_cycle_default(ref position_cycle); fill_position_cycle_default(ref position_cycle);
} }
debug("Position cycle map:");
for (int i = 0;i < position_cycle.length; i++) { for (int i = 0;i < position_cycle.length; i++) {
GLib.stdout.printf(@"$(i)=> $(position_cycle[i])\n"); debug(@"$(i)=> $(position_cycle[i])");
} }
if (app.start_layer > 0 ){ if (app.start_layer > 0) {
this.fix_layer = true; this.fix_layer = true;
this.layer = app.start_layer; this.layer = app.start_layer;
this.active_modifier_by_mouse[1] = this.LAYER_TO_MODIFIERS[this.layer-1, 0]; this.active_modifier_by_mouse[1] = this.LAYER_TO_MODIFIERS[this.layer-1, 0];
@ -229,7 +231,7 @@ namespace NeoLayoutViewer {
this.screen_dim[0] = int.max(1, int.parse(this.config.get("screen_width"))); this.screen_dim[0] = int.max(1, int.parse(this.config.get("screen_width")));
} }
if(screen_dim_auto[1]) { if (screen_dim_auto[1]) {
this.screen_dim[1] = this.get_screen_height(); this.screen_dim[1] = this.get_screen_height();
this.screen_dim_auto[1] = false; // Disables further re-evaluations this.screen_dim_auto[1] = false; // Disables further re-evaluations
} else { } else {
@ -296,12 +298,12 @@ namespace NeoLayoutViewer {
//Nicht selektierbar (für virtuelle Tastatur) //Nicht selektierbar (für virtuelle Tastatur)
this.set_accept_focus((this.config.get("window_selectable") != "0")); this.set_accept_focus((this.config.get("window_selectable") != "0"));
if( this.config.get("show_on_startup") != "0" ){ if (this.config.get("show_on_startup") != "0") {
//Move ist erst nach show() erfolgreich //Move ist erst nach show() erfolgreich
//this.numkeypad_move(int.parse(this.config.get("position"))); //this.numkeypad_move(int.parse(this.config.get("position")));
this.numkeypad_move(this.position_num); this.numkeypad_move(this.position_num);
this.show(); this.show();
}else{ } else {
this.hide(); this.hide();
//this.numkeypad_move(int.parse(this.config.get("position"))); //this.numkeypad_move(int.parse(this.config.get("position")));
this.numkeypad_move(this.position_num); this.numkeypad_move(this.position_num);
@ -328,7 +330,7 @@ namespace NeoLayoutViewer {
} }
} }
public override void hide(){ public override void hide() {
//store current coordinates //store current coordinates
int tmpx; int tmpx;
int tmpy; int tmpy;
@ -341,13 +343,13 @@ namespace NeoLayoutViewer {
base.hide(); base.hide();
} }
public bool toggle(){ public bool toggle() {
if(this.minimized) show(); if (this.minimized) show();
else hide(); else hide();
return this.minimized; return this.minimized;
} }
public void numkeypad_move(int pos){ public void numkeypad_move(int pos) {
var display = Gdk.Display.get_default(); var display = Gdk.Display.get_default();
//var screen = Gdk.Screen.get_default(); //var screen = Gdk.Screen.get_default();
@ -366,7 +368,7 @@ namespace NeoLayoutViewer {
GLib.assert(n_monitors > 0); GLib.assert(n_monitors > 0);
// Automatic set of next position // Automatic set of next position
if( (pos%10) == 0 ){ if ((pos%10) == 0) {
/* Resolve next position */ /* Resolve next position */
pos = this.position_cycle[this.position_num]; pos = this.position_cycle[this.position_num];
} }
@ -374,11 +376,11 @@ namespace NeoLayoutViewer {
// Validate input for manual set of position. // Validate input for manual set of position.
// Note that 'extra monitors', which are not respected in position_cycle, will be ignored. // Note that 'extra monitors', which are not respected in position_cycle, will be ignored.
if ( pos >= this.position_cycle.length ){ if (pos >= this.position_cycle.length) {
pos %= 10; // go back to first monitor pos %= 10; // go back to first monitor
} }
if ( pos < 1 ){ if (pos < 1) {
GLib.stdout.printf(@"Positioning error! Can not handle $(pos). Fall back on pos=5.\n"); GLib.stdout.printf(@"Positioning error! Can not handle $(pos). Fall back on pos=5.\n");
pos = 5; pos = 5;
} }
@ -395,7 +397,7 @@ namespace NeoLayoutViewer {
// Get monitor for this position // Get monitor for this position
int monitor_index = pos/10; int monitor_index = pos/10;
GLib.assert(monitor_index >= 0); GLib.assert(monitor_index >= 0);
if (monitor_index >= n_monitors){ if (monitor_index >= n_monitors) {
monitor_index %= n_monitors; monitor_index %= n_monitors;
} }
@ -416,11 +418,11 @@ namespace NeoLayoutViewer {
Size user_size = this.size_for_monitor[this.monitor_id]; Size user_size = this.size_for_monitor[this.monitor_id];
if (user_size != null && if (user_size != null &&
monitor_rect_dest.width == user_size.monitor_width /* catch resolution changes */ monitor_rect_dest.width == user_size.monitor_width /* catch resolution changes */
){ ) {
// Use stored values // Use stored values
width = user_size.width; width = user_size.width;
height = user_size.height; height = user_size.height;
}else{ } else {
// Default values // Default values
width = get_image_width_for_monitor(monitor_rect_dest.width); width = get_image_width_for_monitor(monitor_rect_dest.width);
height = get_unscaled_height() * width / get_unscaled_width(); height = get_unscaled_height() * width / get_unscaled_width();
@ -438,7 +440,7 @@ namespace NeoLayoutViewer {
this.get_size(out w, out h); // wrong if resolution changed?! TODO: Edit comment this.get_size(out w, out h); // wrong if resolution changed?! TODO: Edit comment
//this.get_size2(out w, out h); // this reflect resolution changes //this.get_size2(out w, out h); // this reflect resolution changes
if (w != width || h != height){ if (w != width || h != height) {
// Window should move on monitor where the window needs an other width. // Window should move on monitor where the window needs an other width.
this.resize(width, height); this.resize(width, height);
this.set_default_size(width, height); this.set_default_size(width, height);
@ -501,24 +503,24 @@ namespace NeoLayoutViewer {
this.move(x, y); this.move(x, y);
} }
public void monitor_move(int i_monitor=-1, bool hide_after_latest=false){ public void monitor_move(int i_monitor=-1, bool hide_after_latest=false) {
if (hide_after_latest ){ if (hide_after_latest) {
if (this.minimized ){ if (this.minimized) {
debug(@"Show minimized window again. $(this.position_num)"); debug(@"Show minimized window again. $(this.position_num)");
show(); show();
return; return;
} }
} }
if ( i_monitor < 0 ){ if (i_monitor < 0) {
numkeypad_move(this.position_num + 10); numkeypad_move(this.position_num + 10);
}else{ } else {
numkeypad_move( 10 * i_monitor + (this.position_num % 10)); numkeypad_move( 10 * i_monitor + (this.position_num % 10));
} }
debug(@"New position: $(this.position_num)"); debug(@"New position: $(this.position_num)");
if( hide_after_latest && this.position_num < 10 && this.already_shown_on_monitor1 ){ if (hide_after_latest && this.position_num < 10 && this.already_shown_on_monitor1) {
// First monitor reached again // First monitor reached again
debug(@"Hide window. $(this.position_num)"); debug(@"Hide window. $(this.position_num)");
@ -531,7 +533,7 @@ namespace NeoLayoutViewer {
this.position_on_hide_x = tmpx; this.position_on_hide_x = tmpx;
this.position_on_hide_y = tmpy; this.position_on_hide_y = tmpy;
} }
if ( this.position_num < 10 ){ if (this.position_num < 10) {
this.already_shown_on_monitor1 = true; this.already_shown_on_monitor1 = true;
} }
} }
@ -686,7 +688,7 @@ namespace NeoLayoutViewer {
this.active_modifier_by_mouse[3] //neo-mod4 this.active_modifier_by_mouse[3] //neo-mod4
] + 1; ] + 1;
}else{ } else {
this.layer = this.MODIFIER_MAP2[ this.layer = this.MODIFIER_MAP2[
this.active_modifier_by_keyboard[1] | this.active_modifier_by_mouse[1], //shift this.active_modifier_by_keyboard[1] | this.active_modifier_by_mouse[1], //shift
this.active_modifier_by_keyboard[2] | this.active_modifier_by_mouse[2], //neo-mod3 this.active_modifier_by_keyboard[2] | this.active_modifier_by_mouse[2], //neo-mod3
@ -743,10 +745,10 @@ namespace NeoLayoutViewer {
this.check_modifier(iet1); this.check_modifier(iet1);
} }
public int get_screen_width(){ public int get_screen_width() {
// Return value derived from config.get("screen_width")) or Gdk.Screen.width() // Return value derived from config.get("screen_width")) or Gdk.Screen.width()
if( this.screen_dim_auto[0] ){ if (this.screen_dim_auto[0]) {
//Re-evaluate //Re-evaluate
#if GTK_MINOR_VERSION == 18 || GTK_MINOR_VERSION == 19 || GTK_MINOR_VERSION == 20 || GTK_MINOR_VERSION == 21 #if GTK_MINOR_VERSION == 18 || GTK_MINOR_VERSION == 19 || GTK_MINOR_VERSION == 20 || GTK_MINOR_VERSION == 21
@ -760,7 +762,7 @@ namespace NeoLayoutViewer {
var screen = this.get_screen(); var screen = this.get_screen();
var monitor = display.get_monitor_at_window(screen.get_active_window()); var monitor = display.get_monitor_at_window(screen.get_active_window());
//Note that type of this is Gtk.Window, but get_active_window() return Gdk.Window //Note that type of this is Gtk.Window, but get_active_window() return Gdk.Window
if( monitor == null){ if (monitor == null) {
monitor = display.get_primary_monitor(); monitor = display.get_primary_monitor();
} }
Gdk.Rectangle geometry = monitor.get_geometry(); Gdk.Rectangle geometry = monitor.get_geometry();
@ -786,10 +788,10 @@ namespace NeoLayoutViewer {
return backgroundW_unscaled; return backgroundW_unscaled;
} }
public int get_screen_height(){ public int get_screen_height() {
// Return value derived from config.get("screen_height")) or Gdk.Screen.height() // Return value derived from config.get("screen_height")) or Gdk.Screen.height()
if( this.screen_dim_auto[1] ){ if (this.screen_dim_auto[1]) {
//Re-evaluate //Re-evaluate
#if GTK_MINOR_VERSION == 18 || GTK_MINOR_VERSION == 19 || GTK_MINOR_VERSION == 20 || GTK_MINOR_VERSION == 21 #if GTK_MINOR_VERSION == 18 || GTK_MINOR_VERSION == 19 || GTK_MINOR_VERSION == 20 || GTK_MINOR_VERSION == 21
@ -803,7 +805,7 @@ namespace NeoLayoutViewer {
var screen = this.get_screen(); var screen = this.get_screen();
var monitor = display.get_monitor_at_window(screen.get_active_window()); var monitor = display.get_monitor_at_window(screen.get_active_window());
//Note that type of this is Gtk.Window, but get_active_window() return Gdk.Window //Note that type of this is Gtk.Window, but get_active_window() return Gdk.Window
if( monitor == null){ if (monitor == null) {
monitor = display.get_primary_monitor(); monitor = display.get_primary_monitor();
} }
Gdk.Rectangle geometry = monitor.get_geometry(); Gdk.Rectangle geometry = monitor.get_geometry();
@ -813,14 +815,14 @@ namespace NeoLayoutViewer {
return screen_dim[1]; return screen_dim[1];
} }
private void fill_position_cycle_default(ref int[] positions){ private void fill_position_cycle_default(ref int[] positions) {
/* Position Next position o o o /* Position Next position o o o
9 8 9 4 7 8 9 8 9 4 7 8
6 5 6 ====> 1 3 9 o o o 6 5 6 ====> 1 3 9 o o o
3 2 3 2 3 6 3 2 3 2 3 6
o o o o o o
Values for monitor 4 are 11,,19 and so on. Values for monitor 4 are 11, , 19 and so on.
Example output: Example output:
positions = { positions = {
@ -833,7 +835,7 @@ namespace NeoLayoutViewer {
GLib.assert( positions.length%10 == 0 && positions.length > 0); GLib.assert( positions.length%10 == 0 && positions.length > 0);
int n_monitors = positions.length/10; int n_monitors = positions.length/10;
for(int i_monitor=0; i_monitor < n_monitors; i_monitor++){ for (int i_monitor=0; i_monitor < n_monitors; i_monitor++) {
int s = i_monitor*10; int s = i_monitor*10;
positions[s] = -1; positions[s] = -1;
positions[s+1] = s + 2; positions[s+1] = s + 2;
@ -848,7 +850,7 @@ namespace NeoLayoutViewer {
} }
} }
private void main_resized(){ private void main_resized() {
// Overwrite stored size for current monitor // Overwrite stored size for current monitor
int width; int width;
@ -857,7 +859,7 @@ namespace NeoLayoutViewer {
Size user_size = this.size_for_monitor[this.monitor_id]; Size user_size = this.size_for_monitor[this.monitor_id];
GLib.assert (user_size != null); GLib.assert (user_size != null);
if (user_size != null ){ if (user_size != null) {
user_size.width = width; user_size.width = width;
user_size.height = height; user_size.height = height;
} }
@ -871,15 +873,15 @@ namespace NeoLayoutViewer {
private int _monitor_width; private int _monitor_width;
public int width { public int width {
get { return _width; } get { return _width; }
set { if (value < 1 ) { _width = 1; }else{ _width = value; } } set { if (value < 1) { _width = 1; } else { _width = value; } }
} }
public int height { public int height {
get { return _height; } get { return _height; }
set { if (value < 1 ) { _height = 1; }else{ _height = value; } } set { if (value < 1) { _height = 1; } else { _height = value; } }
} }
public int monitor_width { public int monitor_width {
get { return _monitor_width; } get { return _monitor_width; }
set { if (value < 1 ) { _monitor_width = 1; }else{ _monitor_width = value; } } set { if (value < 1) { _monitor_width = 1; } else { _monitor_width = value; } }
} }
} }
} }

View File

@ -55,7 +55,7 @@ namespace NeoLayoutViewer {
this.winMain.check_resize.connect(main_resized); this.winMain.check_resize.connect(main_resized);
} }
private void main_resized(){ private void main_resized() {
// Get new window size // Get new window size
int win_width2; int win_width2;
@ -71,8 +71,8 @@ namespace NeoLayoutViewer {
debug(@"Window resize signal. New width/height: $(width)/$(height)\n"); debug(@"Window resize signal. New width/height: $(width)/$(height)\n");
if( win_width2 == 1 && win_height2 == 1){ if (win_width2 == 1 && win_height2 == 1) {
return; // (1,1) send if user show/hides window very fast. return; // (1, 1) send if user show/hides window very fast.
} }
// Eval new image size // Eval new image size