formatting all the way
This commit is contained in:
parent
a332a40df7
commit
da8a5a20ca
|
@ -1,59 +1,59 @@
|
|||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
public Gee.Map<string,string> config;
|
||||
private Gee.Map<string,string> description;// allow optional commenting config entrys.
|
||||
private Gee.Map<string,string> description; // allow optional commenting config entrys.
|
||||
|
||||
public ConfigManager(string path, string conffile) {
|
||||
this.config = new Gee.TreeMap<string, string>();
|
||||
this.description = new Gee.TreeMap<string, string>();
|
||||
|
||||
|
||||
//add defaults values, if key not set in the config file
|
||||
add_defaults();
|
||||
|
||||
//no, it's better to create the conffile in the current dir.
|
||||
//var conffile2 = @"$(path)$(conffile)";
|
||||
|
||||
if(!search_config_file(conffile))
|
||||
if (!search_config_file(conffile)) {
|
||||
create_conf_file(conffile);
|
||||
|
||||
if(search_config_file(conffile))
|
||||
} else {
|
||||
load_config_file(conffile);
|
||||
}
|
||||
|
||||
//add path
|
||||
config.set("path",path);
|
||||
config.set("path", path);
|
||||
|
||||
add_intern_values();
|
||||
}
|
||||
|
||||
public Gee.Map<string, string> getConfig(){
|
||||
public Gee.Map<string, string> getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
private void addSetting(string name, string val, string? comment){
|
||||
private void addSetting(string name, string val, string? comment) {
|
||||
config.set(name, val);
|
||||
if( comment != null )
|
||||
|
||||
if (comment != null) {
|
||||
description.set(name, comment);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Standardwerte der Einstellungen. Sie werden in eine Konfigurationsdatei geschrieben, falls
|
||||
diese Datei nicht vorhanden ist.
|
||||
Standard values. This vaules will be written in the config file if no config file found.
|
||||
*/
|
||||
*/
|
||||
public void add_defaults(){
|
||||
//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("on_top","1", "Show window on top.");
|
||||
addSetting("position","3", "Window position on startup (num pad orientation)");
|
||||
addSetting("width","1000","Width in Pixel. Min_width and max_width bound sensible values. ");//Skalierung, sofern wert zwischen width(resolution)*max_width und width(resolution)*min_width
|
||||
addSetting("min_width","0.25", "Minimal width. 1=full screen width");//Relativ zur Auflösung
|
||||
addSetting("max_width","0.5", "Maximal width. 1=full screen width");//Relativ zur Auflösung
|
||||
//addSetting("move_shortcut","<Mod4><Super_L>R", "Circle the window posisition");
|
||||
addSetting("move_shortcut","<Ctrl><Alt>N", "Circle the window posisition");
|
||||
//addSetting("position_cycle","3 3 9 1 3 9 1 7 7", "List of positions (num pad orientation)");
|
||||
addSetting("position_cycle","2 3 6 1 3 9 4 7 8", "List of positions (num pad orientation)\n# The n-th number marks the next position of the window.\n# Limit the used position to the corners with\n#position_cycle = 3 3 9 1 3 9 1 7 7");
|
||||
addSetting("display_numpad","1", null);
|
||||
addSetting("display_function_keys","0", null);
|
||||
|
@ -65,88 +65,83 @@ namespace NeoLayoutViewer{
|
|||
|
||||
/*
|
||||
Einstellungen, die der Übersicht halber nicht in der Konfigurationsdatei stehen.
|
||||
*/
|
||||
private void add_intern_values(){
|
||||
*/
|
||||
private void add_intern_values() {
|
||||
config.set("numpad_width","350");
|
||||
config.set("function_keys_height","30");
|
||||
}
|
||||
}
|
||||
|
||||
private bool search_config_file(string conffile){
|
||||
var file = File.new_for_path (conffile);
|
||||
private bool search_config_file(string conffile) {
|
||||
var file = File.new_for_path(conffile);
|
||||
return file.query_exists(null);
|
||||
}
|
||||
|
||||
private int create_conf_file(string conffile){
|
||||
var file = File.new_for_path (conffile);
|
||||
private int create_conf_file(string conffile) {
|
||||
var file = File.new_for_path(conffile);
|
||||
|
||||
|
||||
try{
|
||||
try {
|
||||
//Create a new file with this name
|
||||
var file_stream = file.create (FileCreateFlags.NONE);
|
||||
var file_stream = file.create(FileCreateFlags.NONE);
|
||||
|
||||
// Test for the existence of file
|
||||
if (! file.query_exists ()) {
|
||||
stdout.printf ("Can't create config file.\n");
|
||||
if (!file.query_exists()) {
|
||||
stdout.printf("Can't create config file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Write text data to file
|
||||
var data_stream = new DataOutputStream (file_stream);
|
||||
/*
|
||||
data_stream.put_string ("#Show/Hide the window\n");
|
||||
data_stream.put_string ("show_shortcut=<Ctrl><Alt>R\n");
|
||||
data_stream.put_string ("#Show window on top\n");
|
||||
data_stream.put_string ("on_top=1\n");
|
||||
*/
|
||||
foreach( Gee.Map.Entry<string, string> e in this.config.entries){
|
||||
if( this.description.has_key(e.key) ){
|
||||
data_stream.put_string ( "# "+ this.description.get(e.key) +"\n" );
|
||||
var data_stream = new DataOutputStream(file_stream);
|
||||
|
||||
foreach (Gee.Map.Entry<string, string> e in this.config.entries) {
|
||||
|
||||
if (this.description.has_key(e.key)) {
|
||||
data_stream.put_string("# " + this.description.get(e.key) + "\n");
|
||||
}
|
||||
data_stream.put_string ( e.key+" = "+e.value+"\n" );
|
||||
|
||||
data_stream.put_string(e.key + " = " + e.value + "\n");
|
||||
}
|
||||
} // Streams
|
||||
catch ( GLib.IOError e){ return -1; }
|
||||
catch ( GLib.Error e){ return -1; }
|
||||
catch (GLib.IOError e) { return -1; }
|
||||
catch (GLib.Error e) { return -1; }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int load_config_file(string conffile){
|
||||
private int load_config_file(string conffile) {
|
||||
|
||||
// A reference to our file
|
||||
var file = File.new_for_path (conffile);
|
||||
var file = File.new_for_path(conffile);
|
||||
|
||||
try {
|
||||
// Open file for reading and wrap returned FileInputStream into a
|
||||
// DataInputStream, so we can read line by line
|
||||
var in_stream = new DataInputStream (file.read (null));
|
||||
var in_stream = new DataInputStream(file.read(null));
|
||||
string line;
|
||||
string[] split;
|
||||
var comment = new Regex("^#.*$");
|
||||
var regex = new Regex("(#[^=]*)*[ ]*=[ ]*");
|
||||
|
||||
// Read lines until end of file (null) is reached
|
||||
while ((line = in_stream.read_line (null, null)) != null) {
|
||||
//stdout.printf ("%s\n", line);
|
||||
if( comment.match(line)) continue;
|
||||
while ((line = in_stream.read_line(null, null)) != null) {
|
||||
|
||||
if (comment.match(line)) continue;
|
||||
|
||||
split = regex.split(line);
|
||||
if(split.length>1){
|
||||
//debug(split[0]+" "+split[1]+"\n");
|
||||
this.config.set(split[0],split[1]);
|
||||
|
||||
if (split.length > 1) {
|
||||
this.config.set(split[0], split[1]);
|
||||
}
|
||||
}
|
||||
} catch (GLib.IOError e) {
|
||||
error ("%s", e.message);
|
||||
//return -1;
|
||||
} catch (RegexError e) {
|
||||
error ("%s", e.message);
|
||||
//return -1;
|
||||
}catch (GLib.Error e) {
|
||||
} catch (GLib.Error e) {
|
||||
error ("%s", e.message);
|
||||
//return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} // end ConfigManager
|
||||
} // end namespace
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
using Gtk;
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
public class NeoIndicator {
|
||||
|
||||
public class NeoIndicator{
|
||||
private NeoWindow neo_win;
|
||||
private AppIndicator.Indicator indicator;
|
||||
private Gtk.Menu menuMain;
|
||||
|
||||
public NeoIndicator(NeoWindow neo_win ){
|
||||
public NeoIndicator(NeoWindow neo_win) {
|
||||
this.neo_win = neo_win;
|
||||
|
||||
indicator = new AppIndicator.Indicator.with_path("Neo Layout Viewer", "Neo-Icon",
|
||||
|
@ -21,9 +22,9 @@ namespace NeoLayoutViewer{
|
|||
|
||||
}
|
||||
|
||||
public void deactivate()
|
||||
{
|
||||
if(indicator != null) {
|
||||
public void deactivate() {
|
||||
|
||||
if (indicator != null) {
|
||||
indicator.set_status(AppIndicator.IndicatorStatus.PASSIVE);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +34,7 @@ namespace NeoLayoutViewer{
|
|||
menuMain = new Gtk.Menu();
|
||||
|
||||
var menuAnzeigen = new Gtk.MenuItem.with_label("Anzeigen");
|
||||
menuAnzeigen.activate.connect( ()=>{this.neo_win.toggle();} );
|
||||
menuAnzeigen.activate.connect(() => { this.neo_win.toggle(); });
|
||||
menuMain.append(menuAnzeigen);
|
||||
|
||||
var menuAbout = new ImageMenuItem.from_stock(Stock.ABOUT, null);
|
||||
|
@ -48,5 +49,4 @@ namespace NeoLayoutViewer{
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
using Gtk;
|
||||
using Gdk;
|
||||
using X;
|
||||
//using Keysym;//keysymdef.h
|
||||
using Posix;//system-call
|
||||
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
public class ArrayBox {
|
||||
|
||||
public uint[] val;
|
||||
|
||||
public ArrayBox(uint[] val){
|
||||
this.val = val;
|
||||
}
|
||||
|
@ -27,13 +27,13 @@ namespace NeoLayoutViewer{
|
|||
private NeoWindow winMain;
|
||||
|
||||
public KeyOverlay(NeoWindow winMain) {
|
||||
//base(true,0);
|
||||
|
||||
this.set_homogeneous(false);
|
||||
this.set_spacing(0);
|
||||
this.winMain = winMain;
|
||||
this.keysyms = generateKeysyms();
|
||||
|
||||
this.keyBoxes = new Gee.HashMap<int, KeyEventBox>();
|
||||
|
||||
generateKeyevents();
|
||||
|
||||
this.show();
|
||||
|
@ -42,7 +42,7 @@ namespace NeoLayoutViewer{
|
|||
public Gee.HashMap<int, ArrayBox> generateKeysyms(){
|
||||
keysyms = new Gee.HashMap<int, ArrayBox>();
|
||||
|
||||
/* 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. */
|
||||
keysyms.set(8, new ArrayBox({}));
|
||||
keysyms.set( 9, new ArrayBox({ XK_Escape, XK_Escape, XK_Escape, XK_Escape, XK_Escape }));
|
||||
keysyms.set( 10, new ArrayBox({ XK_1, XK_degree, XK_onesuperior, XK_onesubscript, XK_ordfeminine, XK_notsign, 0 /*NoSymbol*/ }));
|
||||
|
@ -304,6 +304,7 @@ namespace NeoLayoutViewer{
|
|||
}
|
||||
|
||||
public void generateKeyevents() {
|
||||
|
||||
Box[] hboxes = {
|
||||
genHBox(), // top row (1,2,3,…)
|
||||
genHBox(), // upper row (x,v,l,…)
|
||||
|
@ -313,7 +314,7 @@ namespace NeoLayoutViewer{
|
|||
genHBox() //function key row
|
||||
};
|
||||
|
||||
if( winMain.config.get("display_function_keys")!="0" ){
|
||||
if (winMain.config.get("display_function_keys") != "0") {
|
||||
this.pack_start( hboxes[5], false, true, 0 );
|
||||
}
|
||||
|
||||
|
@ -323,17 +324,19 @@ namespace NeoLayoutViewer{
|
|||
this.pack_start( hboxes[3], false, true, 0 );
|
||||
this.pack_start( hboxes[4], false, true, 0 );
|
||||
|
||||
foreach( var hbox in hboxes ){
|
||||
foreach( var hbox in hboxes ) {
|
||||
hbox.show();
|
||||
}
|
||||
|
||||
double winWidthUnscaled = 1000.0;
|
||||
double winHeightUnscaled = 250.0;
|
||||
if( winMain.config.get("display_function_keys")=="0" ){
|
||||
|
||||
if (winMain.config.get("display_function_keys") == "0") {
|
||||
winHeightUnscaled -= winMain.function_keys_height;
|
||||
}
|
||||
if( winMain.config.get("display_numpad")=="0" ){
|
||||
winWidthUnscaled -= winMain.numpad_width;
|
||||
|
||||
if (winMain.config.get("display_numpad") == "0") {
|
||||
winWidthUnscaled -= winMain.numpad_width;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
|
@ -347,7 +350,7 @@ namespace NeoLayoutViewer{
|
|||
int posX = 0;
|
||||
int posY = 0;
|
||||
|
||||
if( winMain.config.get("display_function_keys")!="0" ){
|
||||
if (winMain.config.get("display_function_keys") != "0") {
|
||||
//esc
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 9, false, winMain, hboxes[5], 0);
|
||||
//free space
|
||||
|
@ -370,7 +373,8 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 75, false, winMain, hboxes[5], 0);
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 76, false, winMain, hboxes[5], 0);
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 95, false, winMain, hboxes[5], 0);
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
//F12
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 96, false, winMain, hboxes[5], 0);
|
||||
//free space
|
||||
|
@ -379,7 +383,8 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 107, true, winMain, hboxes[5], 0);
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 78, true, winMain, hboxes[5], 0);
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 127, true, winMain, hboxes[5], 0);
|
||||
}else{
|
||||
|
||||
} else {
|
||||
//F12
|
||||
scaledBox(44.0,30.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 96, true, winMain, hboxes[5], 0);
|
||||
}
|
||||
|
@ -404,7 +409,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 20, false, winMain, hboxes[0], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 21 , false, winMain, hboxes[0], 0);
|
||||
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
scaledBox(78.0-1.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 22 , false, winMain, hboxes[0], 0);
|
||||
//free space
|
||||
scaledBox(22.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , -1 , false, winMain, hboxes[0], -1);
|
||||
|
@ -419,7 +424,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 106 , false, winMain, hboxes[0], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 63 , false, winMain, hboxes[0], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 82 , true, winMain, hboxes[0], 0);
|
||||
}else{
|
||||
} else {
|
||||
scaledBox(78.0-1.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 22 , true, winMain, hboxes[0], 0);
|
||||
}
|
||||
//Reset right shift.
|
||||
|
@ -441,7 +446,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 34 , false, winMain, hboxes[1], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 35 , false, winMain, hboxes[1], 0);
|
||||
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
//Halve of Return/Enter
|
||||
scaledBox(62.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 36 , false, winMain, hboxes[1], 0);
|
||||
//free space
|
||||
|
@ -457,7 +462,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 80 , false, winMain, hboxes[1], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 81 , false, winMain, hboxes[1], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 86 , true, winMain, hboxes[1], 0);
|
||||
}else{
|
||||
} else {
|
||||
//Halve of Return/Enter
|
||||
scaledBox(62.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 36 , true, winMain, hboxes[1], 0);
|
||||
}
|
||||
|
@ -484,7 +489,7 @@ namespace NeoLayoutViewer{
|
|||
//right mod3
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 2/*51*/ , false, winMain, hboxes[2], 1);
|
||||
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
//Second halve of Enter/Return
|
||||
scaledBox(49.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 36 , false, winMain, hboxes[2], 0);
|
||||
//free space
|
||||
|
@ -494,7 +499,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 84 , false, winMain, hboxes[2], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 85 , false, winMain, hboxes[2], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 86 , true, winMain, hboxes[2], 0);
|
||||
}else{
|
||||
} else {
|
||||
//Second halve of Enter/Return
|
||||
scaledBox(49.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 36 , true, winMain, hboxes[2], 0);
|
||||
}
|
||||
|
@ -518,7 +523,8 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 59 , false, winMain, hboxes[3], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 60 , false, winMain, hboxes[3], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 61 , false, winMain, hboxes[3], 0);
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
//right shift
|
||||
scaledBox(114.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 1 /*62*/ , false, winMain, hboxes[3], 1);
|
||||
//free space
|
||||
|
@ -532,7 +538,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 88 , false, winMain, hboxes[3], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 89 , false, winMain, hboxes[3], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 104 , true, winMain, hboxes[3], 0);
|
||||
}else{
|
||||
} else {
|
||||
//right shift
|
||||
scaledBox(114.0-1,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 1 /*62*/ , true, winMain, hboxes[3], 1);
|
||||
}
|
||||
|
@ -554,7 +560,7 @@ namespace NeoLayoutViewer{
|
|||
//free space
|
||||
scaledBox(40.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , -1 , false, winMain, hboxes[4], -1);
|
||||
|
||||
if( winMain.config.get("display_numpad")!="0" ){
|
||||
if (winMain.config.get("display_numpad") != "0") {
|
||||
// right ctrl
|
||||
scaledBox(61.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 4/*105*/ , false, winMain, hboxes[4], 3);
|
||||
//free space
|
||||
|
@ -569,7 +575,7 @@ namespace NeoLayoutViewer{
|
|||
scaledBox(88.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 90 , false, winMain, hboxes[4], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 91 , false, winMain, hboxes[4], 0);
|
||||
scaledBox(44.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 104 , false, winMain, hboxes[4], 0);
|
||||
}else{
|
||||
} else {
|
||||
// right ctrl
|
||||
scaledBox(61.0,44.0,ref posXUnscaled, ref posYUnscaled, ref posX, ref posY, scaleX, scaleY , 4/*105*/ , false, winMain, hboxes[4], 3);
|
||||
}
|
||||
|
@ -586,57 +592,57 @@ namespace NeoLayoutViewer{
|
|||
ref double posXUnscaled, ref double posYUnscaled,
|
||||
ref int posX, ref int posY,
|
||||
double scaleX, double scaleY,
|
||||
int keycode, bool vertical, NeoWindow winMain, Box box, int boxtype ){
|
||||
int keycode, bool vertical, NeoWindow winMain, Box box, int boxtype) {
|
||||
|
||||
int width = (int) GLib.Math.floor( (posXUnscaled + widthUnscaled)*scaleX - posX ) ;
|
||||
int height = (int) GLib.Math.floor( (posYUnscaled + heightUnscaled)*scaleY - posY);
|
||||
int width = (int)GLib.Math.floor((posXUnscaled + widthUnscaled) * scaleX - posX );
|
||||
int height = (int)GLib.Math.floor((posYUnscaled + heightUnscaled) * scaleY - posY);
|
||||
|
||||
if( vertical){
|
||||
if (vertical) {
|
||||
posYUnscaled += heightUnscaled;
|
||||
posY += height;
|
||||
}else{
|
||||
} else {
|
||||
posXUnscaled += widthUnscaled;
|
||||
posX += width;
|
||||
}
|
||||
|
||||
KeyEventBox keybox;
|
||||
switch (boxtype){
|
||||
case 0:
|
||||
// Normale Taste
|
||||
ArrayBox ks = this.keysyms.get(keycode);
|
||||
keybox = new KeyEventBox(winMain, width, height, ref ks.val );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 1:
|
||||
// Modifier, die andere Buchstabenebenen aktivieren. Zusätzlich Ebenen-Bild einblenden.
|
||||
keybox = new KeyEventBox.modifier(winMain, width, height, keycode /*=modifier array index*/ );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
//Andere Modifier (CTRL, Alt,... )
|
||||
case 2: //left ctrl
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_ctrl_left_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 3: //right ctrl
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_ctrl_right_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 4: //left alt
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_alt_left_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
default:
|
||||
// Fläche ohne Funktion
|
||||
keybox = new KeyEventBox.freeArea(winMain, width, height );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
}
|
||||
switch (boxtype) {
|
||||
case 0:
|
||||
// Normale Taste
|
||||
ArrayBox ks = this.keysyms.get(keycode);
|
||||
keybox = new KeyEventBox(winMain, width, height, ref ks.val );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 1:
|
||||
// Modifier, die andere Buchstabenebenen aktivieren. Zusätzlich Ebenen-Bild einblenden.
|
||||
keybox = new KeyEventBox.modifier(winMain, width, height, keycode /*=modifier array index*/ );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
//Andere Modifier (CTRL, Alt,... )
|
||||
case 2: //left ctrl
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_ctrl_left_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 3: //right ctrl
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_ctrl_right_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
case 4: //left alt
|
||||
keybox = new KeyEventBox.modifier2(winMain, width, height, keycode /*modifier array index */, "tastatur_alt_left_2.png" );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
default:
|
||||
// Fläche ohne Funktion
|
||||
keybox = new KeyEventBox.freeArea(winMain, width, height );
|
||||
this.keyBoxes.set(keycode, keybox);
|
||||
box.pack_start(keybox, false, true, 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return keybox;
|
||||
|
@ -666,7 +672,7 @@ namespace NeoLayoutViewer{
|
|||
*/
|
||||
private static const short[] layer_permutation = {0,1,2,3,5,4,6};
|
||||
|
||||
private KeyEventBox.all(NeoWindow winMain, int width, int height){
|
||||
private KeyEventBox.all(NeoWindow winMain, int width, int height) {
|
||||
this.winMain = winMain;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
@ -675,46 +681,47 @@ namespace NeoLayoutViewer{
|
|||
this.show();
|
||||
}
|
||||
|
||||
public KeyEventBox(NeoWindow winMain, int width, int height , ref uint[] keysym){
|
||||
public KeyEventBox(NeoWindow winMain, int width, int height , ref uint[] keysym) {
|
||||
this.all(winMain, width, height);
|
||||
this.keysym = keysym;
|
||||
|
||||
this.button_press_event.connect ((event) => {
|
||||
if( event.button != 1){
|
||||
return false;
|
||||
}
|
||||
|
||||
uint ks = this.keysym[NeoLayoutViewer.KeyEventBox.layer_permutation[winMain.layer]-1];
|
||||
int modi = winMain.getActiveModifierMask({4,5}); //ctrl+alt mask
|
||||
if( ks < 1 ) return false;
|
||||
|
||||
if( modi == 0 || true){
|
||||
// Alt-Mask do not work :-(
|
||||
keysend(ks,modi);
|
||||
}else{
|
||||
debug("Zweiter Modi");
|
||||
keysend2(ks,modi & Gdk.ModifierType.CONTROL_MASK, modi & Gdk.ModifierType.MOD1_MASK );
|
||||
}
|
||||
if (event.button != 1){
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
uint ks = this.keysym[NeoLayoutViewer.KeyEventBox.layer_permutation[winMain.layer] - 1];
|
||||
int modi = winMain.getActiveModifierMask({4,5}); //ctrl+alt mask
|
||||
if (ks < 1) return false;
|
||||
|
||||
if (modi == 0 || true) {
|
||||
// Alt-Mask do not work :-(
|
||||
keysend(ks,modi);
|
||||
} else {
|
||||
debug("Zweiter Modi");
|
||||
keysend2(ks,modi & Gdk.ModifierType.CONTROL_MASK, modi & Gdk.ModifierType.MOD1_MASK);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public KeyEventBox.modifier(NeoWindow winMain, int width, int height , int modifier_index ){
|
||||
public KeyEventBox.modifier(NeoWindow winMain, int width, int height , int modifier_index) {
|
||||
this.all(winMain, width, height);
|
||||
this.modifier_index = modifier_index;
|
||||
|
||||
this.button_press_event.connect ((event) => {
|
||||
if( winMain.active_modifier_by_mouse[this.modifier_index] == 0){
|
||||
winMain.change_active_modifier( this.modifier_index, false, 1 );
|
||||
//winMain.status.set_label(@"Activate\nModifier $(this.modifier_index)");
|
||||
}else{
|
||||
winMain.change_active_modifier( this.modifier_index, false, 0 );
|
||||
//winMain.status.set_label(@"Deactivate\nModifier $(this.modifier_index)");
|
||||
if (winMain.active_modifier_by_mouse[this.modifier_index] == 0) {
|
||||
winMain.change_active_modifier( this.modifier_index, false, 1 );
|
||||
//winMain.status.set_label(@"Activate\nModifier $(this.modifier_index)");
|
||||
} else {
|
||||
winMain.change_active_modifier( this.modifier_index, false, 0 );
|
||||
//winMain.status.set_label(@"Deactivate\nModifier $(this.modifier_index)");
|
||||
}
|
||||
winMain.redraw();
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public KeyEventBox.modifier2(NeoWindow winMain, int width, int height , int modifier_index, string pressed_key_image ){
|
||||
|
@ -722,19 +729,20 @@ namespace NeoLayoutViewer{
|
|||
this.modifier_index = modifier_index;
|
||||
|
||||
this.button_press_event.connect ((event) => {
|
||||
if( winMain.active_modifier_by_mouse[this.modifier_index] == 0){
|
||||
winMain.change_active_modifier( 1, false, 0 );
|
||||
winMain.change_active_modifier( 2, false, 0 );
|
||||
winMain.change_active_modifier( 3, false, 0 );
|
||||
winMain.change_active_modifier( this.modifier_index, false, 1 );
|
||||
this.image.show();
|
||||
}else{
|
||||
winMain.change_active_modifier( this.modifier_index, false, 0 );
|
||||
this.image.hide();
|
||||
if (winMain.active_modifier_by_mouse[this.modifier_index] == 0) {
|
||||
winMain.change_active_modifier( 1, false, 0 );
|
||||
winMain.change_active_modifier( 2, false, 0 );
|
||||
winMain.change_active_modifier( 3, false, 0 );
|
||||
winMain.change_active_modifier( this.modifier_index, false, 1 );
|
||||
this.image.show();
|
||||
} else {
|
||||
winMain.change_active_modifier( this.modifier_index, false, 0 );
|
||||
this.image.hide();
|
||||
}
|
||||
|
||||
winMain.redraw();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
// Image of pressed Button
|
||||
Gdk.Pixbuf image_buffer = winMain.open_image_str(@"assets/neo2.0/$(pressed_key_image)");
|
||||
|
@ -752,7 +760,7 @@ namespace NeoLayoutViewer{
|
|||
|
||||
}
|
||||
|
||||
public KeyEventBox.freeArea(NeoWindow winMain, int width, int height ){
|
||||
public KeyEventBox.freeArea(NeoWindow winMain, int width, int height) {
|
||||
this.all(winMain, width, height);
|
||||
}
|
||||
|
||||
|
@ -761,23 +769,12 @@ namespace NeoLayoutViewer{
|
|||
* the widget how large it wishes to be. It's not guaranteed
|
||||
* that Gtk+ will actually give this size to the widget.
|
||||
*/
|
||||
/*
|
||||
public override void get_preferred_size(
|
||||
out Gtk.Requisition minimal_size,
|
||||
out Gtk.Requisition natural_size ) {
|
||||
|
||||
minimal_size.width = width ;
|
||||
minimal_size.height = height;
|
||||
|
||||
natural_size.width = width ;
|
||||
natural_size.height = height;
|
||||
}
|
||||
*/
|
||||
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;
|
||||
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;
|
||||
natural_height = height;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
using X;
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
/**
|
||||
* Modification of http://www.linux-nantes.org/~fmonnier/ocaml/Xlib/doc/Xlib.html by
|
||||
* Oliver Sauder <os@esite.ch>
|
||||
*/
|
||||
public class KeybindingManager : GLib.Object
|
||||
{
|
||||
public class KeybindingManager : GLib.Object {
|
||||
|
||||
private NeoWindow neo_win;
|
||||
|
||||
/**
|
||||
* list of binded keybindings
|
||||
*/
|
||||
private Gee.List<Keybinding> bindings = new Gee.ArrayList<Keybinding>();
|
||||
|
||||
/**
|
||||
* locked modifiers used to grab all keys whatever lock key
|
||||
* is pressed.
|
||||
|
@ -33,11 +36,9 @@ namespace NeoLayoutViewer{
|
|||
/**
|
||||
* Helper class to store keybinding
|
||||
*/
|
||||
private class Keybinding
|
||||
{
|
||||
public Keybinding(string accelerator, int keycode,
|
||||
Gdk.ModifierType modifiers, KeybindingHandlerFunc handler)
|
||||
{
|
||||
private class Keybinding {
|
||||
|
||||
public Keybinding(string accelerator, int keycode, Gdk.ModifierType modifiers, KeybindingHandlerFunc handler) {
|
||||
this.accelerator = accelerator;
|
||||
this.keycode = keycode;
|
||||
this.modifiers = modifiers;
|
||||
|
@ -57,13 +58,14 @@ namespace NeoLayoutViewer{
|
|||
*/
|
||||
public delegate void KeybindingHandlerFunc(Gdk.Event event);
|
||||
|
||||
public KeybindingManager(NeoWindow neo_win)
|
||||
{
|
||||
public KeybindingManager(NeoWindow neo_win) {
|
||||
this.neo_win = neo_win;
|
||||
|
||||
// init filter to retrieve X.Events
|
||||
unowned Gdk.Window rootwin = Gdk.get_default_root_window();
|
||||
if(rootwin != null) {
|
||||
|
||||
if (rootwin != null) {
|
||||
|
||||
rootwin.add_filter(event_filter);
|
||||
|
||||
unowned X.Display display = Gdk.x11_get_default_xdisplay();
|
||||
|
@ -79,7 +81,7 @@ namespace NeoLayoutViewer{
|
|||
modifier_keycodes[8] = display.keysym_to_keycode(XK_Alt_L);
|
||||
modifier_keycodes[9] = display.keysym_to_keycode(XK_Alt_R);
|
||||
|
||||
Timeout.add (100, modifier_timer);
|
||||
Timeout.add(100, modifier_timer);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +92,8 @@ namespace NeoLayoutViewer{
|
|||
* @param accelerator accelerator parsable by Gtk.accelerator_parse
|
||||
* @param handler handler called when given accelerator is pressed
|
||||
*/
|
||||
public void bind(string accelerator, KeybindingHandlerFunc handler)
|
||||
{
|
||||
public void bind(string accelerator, KeybindingHandlerFunc handler) {
|
||||
|
||||
debug("Binding key " + accelerator);
|
||||
|
||||
// convert accelerator
|
||||
|
@ -102,7 +104,7 @@ namespace NeoLayoutViewer{
|
|||
unowned X.Display display = Gdk.x11_get_default_xdisplay();
|
||||
int keycode = display.keysym_to_keycode(keysym);
|
||||
|
||||
if(keycode != 0) {
|
||||
if (keycode != 0) {
|
||||
X.Window root_window = Gdk.x11_get_default_root_xwindow();
|
||||
|
||||
// trap XErrors to avoid closing of application
|
||||
|
@ -111,9 +113,8 @@ namespace NeoLayoutViewer{
|
|||
|
||||
// grab key finally
|
||||
// also grab all keys which are combined with a lock key such NumLock
|
||||
foreach(uint lock_modifier in lock_modifiers) {
|
||||
display.grab_key(keycode, modifiers|lock_modifier, root_window, false,
|
||||
X.GrabMode.Async, X.GrabMode.Async);
|
||||
foreach (uint lock_modifier in lock_modifiers) {
|
||||
display.grab_key(keycode, modifiers|lock_modifier, root_window, false, X.GrabMode.Async, X.GrabMode.Async);
|
||||
}
|
||||
|
||||
// wait until all X request have been processed
|
||||
|
@ -123,17 +124,17 @@ namespace NeoLayoutViewer{
|
|||
Keybinding binding = new Keybinding(accelerator, keycode, modifiers, handler);
|
||||
bindings.add(binding);
|
||||
|
||||
debug("Successfully binded key " + accelerator);
|
||||
debug("Successfully bound key " + accelerator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbind given accelerator.
|
||||
*
|
||||
* @param accelerator accelerator parsable by Gtk.accelerator_parse
|
||||
*/
|
||||
|
||||
public void unbind(string accelerator)
|
||||
{
|
||||
public void unbind(string accelerator) {
|
||||
debug("Unbinding key " + accelerator);
|
||||
|
||||
unowned X.Display display = Gdk.x11_get_default_xdisplay();
|
||||
|
@ -141,11 +142,15 @@ namespace NeoLayoutViewer{
|
|||
|
||||
// unbind all keys with given accelerator
|
||||
Gee.List<Keybinding> remove_bindings = new Gee.ArrayList<Keybinding>();
|
||||
foreach(Keybinding binding in bindings) {
|
||||
if(str_equal(accelerator, binding.accelerator)) {
|
||||
foreach(uint lock_modifier in lock_modifiers) {
|
||||
|
||||
foreach (Keybinding binding in bindings) {
|
||||
|
||||
if (str_equal(accelerator, binding.accelerator)) {
|
||||
|
||||
foreach (uint lock_modifier in lock_modifiers) {
|
||||
display.ungrab_key(binding.keycode, binding.modifiers, root_window);
|
||||
}
|
||||
|
||||
remove_bindings.add(binding);
|
||||
}
|
||||
}
|
||||
|
@ -158,8 +163,7 @@ namespace NeoLayoutViewer{
|
|||
/**
|
||||
* Event filter method needed to fetch X.Events
|
||||
*/
|
||||
private Gdk.FilterReturn event_filter(Gdk.XEvent gdk_xevent, Gdk.Event gdk_event)
|
||||
{
|
||||
private Gdk.FilterReturn event_filter(Gdk.XEvent gdk_xevent, Gdk.Event gdk_event) {
|
||||
Gdk.FilterReturn filter_return = Gdk.FilterReturn.CONTINUE;
|
||||
#if VALA_0_16 || VALA_0_17
|
||||
X.Event* xevent = (X.Event*) gdk_xevent;
|
||||
|
@ -168,11 +172,13 @@ namespace NeoLayoutViewer{
|
|||
X.Event* xevent = (X.Event*) pointer;
|
||||
#endif
|
||||
|
||||
if(xevent->type == X.EventType.KeyPress) {
|
||||
if (xevent->type == X.EventType.KeyPress) {
|
||||
|
||||
foreach(Keybinding binding in bindings) {
|
||||
// remove NumLock, CapsLock and ScrollLock from key state
|
||||
uint event_mods = xevent.xkey.state & ~ (lock_modifiers[7]);
|
||||
if(xevent->xkey.keycode == binding.keycode && event_mods == binding.modifiers) {
|
||||
|
||||
if (xevent->xkey.keycode == binding.keycode && event_mods == binding.modifiers) {
|
||||
// call all handlers with pressed key and modifiers
|
||||
binding.handler(gdk_event);
|
||||
}
|
||||
|
@ -183,20 +189,20 @@ namespace NeoLayoutViewer{
|
|||
}
|
||||
|
||||
/*
|
||||
Checks periodical which modifier are pressed.
|
||||
Checks periodically which modifier are pressed.
|
||||
*/
|
||||
private bool modifier_timer(){
|
||||
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]);
|
||||
|
||||
// Convert modifier keys to modifier/layer
|
||||
neo_win.change_active_modifier( 1, true, (int) ( ( modifier_pressed[0] | modifier_pressed[1] )
|
||||
!= (checkCapsLock(display)?1:0) ) );
|
||||
neo_win.change_active_modifier( 2, true, (int) ( modifier_pressed[2] | modifier_pressed[3] ) );
|
||||
neo_win.change_active_modifier( 3, true, (int) ( modifier_pressed[4] | modifier_pressed[5] ) );
|
||||
neo_win.change_active_modifier( 4, true, (int) ( modifier_pressed[6] | modifier_pressed[7] ) );
|
||||
neo_win.change_active_modifier( 5, true, (int) ( modifier_pressed[8] | modifier_pressed[9] ) );
|
||||
neo_win.change_active_modifier(1, true, (int)((modifier_pressed[0] | modifier_pressed[1])
|
||||
!= (checkCapsLock(display) ? 1 : 0)) );
|
||||
neo_win.change_active_modifier(2, true, (int)(modifier_pressed[2] | modifier_pressed[3]));
|
||||
neo_win.change_active_modifier(3, true, (int)(modifier_pressed[4] | modifier_pressed[5]));
|
||||
neo_win.change_active_modifier(4, true, (int)(modifier_pressed[6] | modifier_pressed[7]));
|
||||
neo_win.change_active_modifier(5, true, (int)(modifier_pressed[8] | modifier_pressed[9]));
|
||||
|
||||
neo_win.redraw();
|
||||
|
||||
|
|
|
@ -13,16 +13,17 @@ namespace NeoLayoutViewer{
|
|||
public NeoIndicator neo_indicator; //for gnome3.x
|
||||
#endif
|
||||
|
||||
public static int main (string[] args) {
|
||||
public static int main(string[] args) {
|
||||
|
||||
string slayer;
|
||||
if( args.length<2) {
|
||||
slayer="1";
|
||||
}else{
|
||||
slayer=args[1];
|
||||
|
||||
if (args.length < 2) {
|
||||
slayer = "1";
|
||||
} else {
|
||||
slayer = args[1];
|
||||
}
|
||||
|
||||
Gtk.init (ref args);
|
||||
Gtk.init(ref args);
|
||||
|
||||
|
||||
//Get program path (no binding for getcwd found…)
|
||||
|
@ -36,12 +37,12 @@ namespace NeoLayoutViewer{
|
|||
debug(@"Path: $path");
|
||||
|
||||
configm = new ConfigManager(path,"neo_layout_viewer.conf");
|
||||
|
||||
neo_win = new NeoWindow (slayer, configm.getConfig());
|
||||
|
||||
var app = showPreviousInstance("org.gnome.neo_layout_viewer", neo_win);
|
||||
if( app == null){
|
||||
return 0;
|
||||
|
||||
if (app == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
manager = new KeybindingManager(neo_win);
|
||||
|
@ -57,12 +58,9 @@ namespace NeoLayoutViewer{
|
|||
manager.bind(configm.getConfig().get("show_shortcut"), ()=>{neo_win.toggle();});
|
||||
manager.bind(configm.getConfig().get("move_shortcut"), ()=>{neo_win.numkeypad_move(0);});
|
||||
|
||||
//neo_win.show_all ();
|
||||
//neo_win.hide_all();
|
||||
|
||||
//move window (Fehlerquelle: config von configm ist im allgemeinen nicht gleich neo_win.config?! Derzeit gleiches Objekt.)
|
||||
|
||||
Gtk.main ();
|
||||
Gtk.main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,24 +3,23 @@ using Gdk;
|
|||
using X; //keysym.h
|
||||
using Posix;//system-calls
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
|
||||
public class Modkey{
|
||||
public class Modkey {
|
||||
public Gtk.Image modKeyImage;
|
||||
public int modifier_index;
|
||||
public int active;
|
||||
|
||||
public Modkey(ref Gtk.Image i, int m){
|
||||
public Modkey(ref Gtk.Image i, int m) {
|
||||
this.modKeyImage = i;
|
||||
this.modifier_index = m;
|
||||
this.active = 0;
|
||||
}
|
||||
|
||||
public void change( int new_state ){
|
||||
if( new_state == this.active ) return;
|
||||
public void change (int new_state) {
|
||||
if (new_state == this.active) return;
|
||||
this.active = new_state;
|
||||
if( this.active == 0){
|
||||
if (this.active == 0) {
|
||||
modKeyImage.hide();
|
||||
}else{
|
||||
modKeyImage.show();
|
||||
|
@ -77,6 +76,19 @@ namespace NeoLayoutViewer{
|
|||
{0,1,0,3,1,3},
|
||||
{0,1,2,0,4,2} };
|
||||
|
||||
/*
|
||||
Modifier können per Tastatur und Maus aktiviert werden. Diese Abbildung entscheidet,
|
||||
wie bei einer Zustandsänderung verfahren werden soll.
|
||||
k,m,K,M ∈ {0,1}.
|
||||
k - Taste wurde gedrückt gehalten
|
||||
m - Taste wurde per Mausklick selektiert.
|
||||
K - Taste wird gedrückt
|
||||
M - Taste wird per Mausklick selektiert.
|
||||
|
||||
k' = f(k,m,K,M). Und wegen der Symmetrie(!)
|
||||
m' = f(m,k,M,K)
|
||||
Siehe auch change_active_modifier(…).
|
||||
*/
|
||||
private short[,,,] MODIFIER_KEYBOARD_MOUSE_MAP = {
|
||||
// k = f(k,m,K,M,) and m = f(m,k,M,K)
|
||||
{ { {0, 0} , {1, 0} } , // 0000, 0001; 0010, 0011;
|
||||
|
@ -112,11 +124,11 @@ namespace NeoLayoutViewer{
|
|||
this.position_num = int.max(int.min(int.parse(config.get("position")),9),1);
|
||||
|
||||
//Anlegen des Arrays, welches den Positionsdurchlauf beschreibt.
|
||||
try{
|
||||
try {
|
||||
var space = new Regex(" ");
|
||||
string[] split = space.split(config.get("position_cycle"));
|
||||
position_cycle = new int[int.max(9,split.length)];
|
||||
for(int i=0;i<split.length;i++){
|
||||
for (int i = 0;i < split.length; i++) {
|
||||
position_cycle[i] = int.max(int.min(int.parse(split[i]),9),1);//Zulässiger Bereich: 1-9
|
||||
}
|
||||
} catch (RegexError e) {
|
||||
|
@ -125,19 +137,18 @@ namespace NeoLayoutViewer{
|
|||
|
||||
|
||||
this.layer = int.parse(slayer);
|
||||
if(this.layer<1 || this.layer>6) {this.layer = 1; }
|
||||
if (this.layer < 1 || this.layer > 6) { this.layer = 1; }
|
||||
|
||||
//Lade die Pngs der sechs Ebenen
|
||||
this.load_image_buffer();
|
||||
this.image = new Gtk.Image();//.from_pixbuf(this.image_buffer[layer]);
|
||||
|
||||
image.show();
|
||||
render_page ();
|
||||
|
||||
render_page();
|
||||
var fixed = new Fixed();
|
||||
|
||||
fixed.put(this.image, 0, 0);
|
||||
fixed.put( new KeyOverlay(this) , 0, 0);
|
||||
fixed.put(new KeyOverlay(this), 0, 0);
|
||||
|
||||
this.status = new Label("");
|
||||
status.show();
|
||||
|
@ -152,33 +163,34 @@ namespace NeoLayoutViewer{
|
|||
fixed.show();
|
||||
|
||||
//Fenstereigenschaften setzen
|
||||
this.key_press_event.connect (on_key_pressed);
|
||||
this.button_press_event.connect (on_button_pressed);
|
||||
this.destroy.connect (Gtk.main_quit);
|
||||
this.key_press_event.connect(on_key_pressed);
|
||||
this.button_press_event.connect(on_button_pressed);
|
||||
this.destroy.connect(Gtk.main_quit);
|
||||
|
||||
this.set_gravity(Gdk.Gravity.SOUTH);
|
||||
this.decorated = (config.get("window_decoration") != "0" );
|
||||
this.decorated = (config.get("window_decoration") != "0");
|
||||
this.skip_taskbar_hint = true;
|
||||
|
||||
//Icon des Fensters
|
||||
this.icon = this.image_buffer[0];
|
||||
|
||||
//Nicht selektierbar (für virtuelle Tastatur)
|
||||
this.set_accept_focus( (config.get("window_selectable")!="0") );
|
||||
this.set_accept_focus((config.get("window_selectable") != "0"));
|
||||
|
||||
screen_dim_auto[0] = (config.get("screen_width") == "auto");
|
||||
screen_dim_auto[0] = (config.get("screen_width") == "auto");
|
||||
screen_dim_auto[1] = (config.get("screen_height") == "auto");
|
||||
|
||||
//Dimension des Bildschirms festlegen
|
||||
if( screen_dim_auto[0]){
|
||||
if (screen_dim_auto[0]) {
|
||||
screen_dim[0] = Gdk.Screen.width();
|
||||
}else{
|
||||
screen_dim[0] = int.max(1,int.parse( config.get("screen_width") ));
|
||||
} else {
|
||||
screen_dim[0] = int.max(1, int.parse(config.get("screen_width")));
|
||||
}
|
||||
if( screen_dim_auto[1]){
|
||||
|
||||
if(screen_dim_auto[1]) {
|
||||
screen_dim[1] = Gdk.Screen.height();
|
||||
}else{
|
||||
screen_dim[1] = int.max(1,int.parse( config.get("screen_height") ));
|
||||
} else {
|
||||
screen_dim[1] = int.max(1, int.parse(config.get("screen_height")));
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,15 +200,16 @@ namespace NeoLayoutViewer{
|
|||
this.numkeypad_move(int.parse(config.get("position")));
|
||||
}
|
||||
|
||||
public override void show(){
|
||||
public override void show() {
|
||||
this.minimized = false;
|
||||
base.show();
|
||||
this.move(this.position_on_hide_x,this.position_on_hide_y);
|
||||
this.move(this.position_on_hide_x, this.position_on_hide_y);
|
||||
|
||||
if( config.get("on_top")=="1")
|
||||
if (config.get("on_top") == "1") {
|
||||
this.set_keep_above(true);
|
||||
else
|
||||
} else {
|
||||
this.present();
|
||||
}
|
||||
}
|
||||
|
||||
public override void hide(){
|
||||
|
@ -224,13 +237,13 @@ namespace NeoLayoutViewer{
|
|||
}
|
||||
|
||||
public void numkeypad_move(int pos){
|
||||
int screen_width = (screen_dim_auto[0]?Gdk.Screen.width():screen_dim[0]);
|
||||
int screen_height = (screen_dim_auto[1]?Gdk.Screen.height():screen_dim[1]);
|
||||
int screen_width = (screen_dim_auto[0] ? Gdk.Screen.width() : screen_dim[0]);
|
||||
int screen_height = (screen_dim_auto[1] ? Gdk.Screen.height() : screen_dim[1]);
|
||||
|
||||
int x,y,w,h;
|
||||
this.get_size(out w,out h);
|
||||
this.get_size(out w, out h);
|
||||
|
||||
switch (pos){
|
||||
switch(pos) {
|
||||
case 0: //Zur nächsten Position wechseln
|
||||
numkeypad_move(this.position_cycle[this.position_num-1]);
|
||||
return;
|
||||
|
@ -239,44 +252,44 @@ namespace NeoLayoutViewer{
|
|||
y = 0;
|
||||
break;
|
||||
case 8:
|
||||
x = (screen_width-w)/2;
|
||||
x = (screen_width - w) / 2;
|
||||
y = 0;
|
||||
break;
|
||||
case 9:
|
||||
x = screen_width-w;
|
||||
x = screen_width - w;
|
||||
y = 0;
|
||||
break;
|
||||
case 4:
|
||||
x = 0;
|
||||
y = (screen_height-h)/2;
|
||||
y = (screen_height - h) / 2;
|
||||
break;
|
||||
case 5:
|
||||
x = (screen_width-w)/2;
|
||||
y = (screen_height-h)/2;
|
||||
x = (screen_width - w) / 2;
|
||||
y = (screen_height - h) / 2;
|
||||
break;
|
||||
case 6:
|
||||
x = screen_width-w;
|
||||
y = (screen_height-h)/2;
|
||||
x = screen_width - w;
|
||||
y = (screen_height - h) / 2;
|
||||
break;
|
||||
case 1:
|
||||
x = 0;
|
||||
y = screen_height-h;
|
||||
y = screen_height - h;
|
||||
break;
|
||||
case 2:
|
||||
x = (screen_width-w)/2;
|
||||
y = screen_height-h;
|
||||
x = (screen_width - w) / 2;
|
||||
y = screen_height - h;
|
||||
break;
|
||||
default:
|
||||
x = screen_width-w;
|
||||
y = screen_height-h;
|
||||
x = screen_width - w;
|
||||
y = screen_height - h;
|
||||
break;
|
||||
}
|
||||
|
||||
this.position_num = pos;
|
||||
this.move(x,y);
|
||||
this.move(x, y);
|
||||
}
|
||||
|
||||
public Gdk.Pixbuf open_image (int layer) {
|
||||
public Gdk.Pixbuf open_image(int layer) {
|
||||
var bildpfad = "assets/neo2.0/tastatur_neo_Ebene%i.png".printf(layer);
|
||||
return open_image_str(bildpfad);
|
||||
}
|
||||
|
@ -294,26 +307,26 @@ namespace NeoLayoutViewer{
|
|||
this.image_buffer[0] = open_image_str(@"$(this.config.get("path"))assets/icons/Neo-Icon.png");
|
||||
|
||||
int screen_width = Gdk.Screen.width();
|
||||
int max_width = (int) ( double.parse( this.config.get("max_width") )*screen_width );
|
||||
int min_width = (int) ( double.parse( this.config.get("min_width") )*screen_width );
|
||||
int width = int.min(int.max(int.parse( config.get("width") ),min_width),max_width);
|
||||
int w,h;
|
||||
int max_width = (int) (double.parse(this.config.get("max_width")) * screen_width);
|
||||
int min_width = (int) (double.parse(this.config.get("min_width")) * screen_width);
|
||||
int width = int.min(int.max(int.parse(config.get("width")),min_width),max_width);
|
||||
int w, h;
|
||||
|
||||
this.numpad_width = int.parse(config.get("numpad_width"));
|
||||
this.function_keys_height = int.parse(config.get("function_keys_height"));
|
||||
|
||||
for (int i=1; i<7; i++){
|
||||
for (int i = 1; i < 7; i++) {
|
||||
this.image_buffer[i] = open_image(i);
|
||||
|
||||
//Funktionstasten ausblennden, falls gefordert.
|
||||
if( config.get("display_function_keys")=="0" ){
|
||||
if (config.get("display_function_keys") == "0") {
|
||||
var tmp = new Gdk.Pixbuf(image_buffer[i].colorspace,image_buffer[i].has_alpha,image_buffer[i].bits_per_sample, image_buffer[i].width ,image_buffer[i].height-function_keys_height);
|
||||
this.image_buffer[i].copy_area(0,function_keys_height,tmp.width,tmp.height,tmp,0,0);
|
||||
this.image_buffer[i] = tmp;
|
||||
}
|
||||
|
||||
//Numpad-Teil abschneiden, falls gefordert.
|
||||
if( config.get("display_numpad")=="0" ){
|
||||
if (config.get("display_numpad") == "0") {
|
||||
var tmp = new Gdk.Pixbuf(image_buffer[i].colorspace,image_buffer[i].has_alpha,image_buffer[i].bits_per_sample, image_buffer[i].width-numpad_width ,image_buffer[i].height);
|
||||
this.image_buffer[i].copy_area(0,0,tmp.width,tmp.height,tmp,0,0);
|
||||
this.image_buffer[i] = tmp;
|
||||
|
@ -322,7 +335,7 @@ namespace NeoLayoutViewer{
|
|||
//Bilder einmaling beim Laden skalieren. (Keine spätere Skalierung durch Größenänderung des Fensters)
|
||||
w = this.image_buffer[i].width;
|
||||
h = this.image_buffer[i].height;
|
||||
this.image_buffer[i] = this.image_buffer[i].scale_simple(width, h*width/w,Gdk.InterpType.BILINEAR);
|
||||
this.image_buffer[i] = this.image_buffer[i].scale_simple(width, h * width / w, Gdk.InterpType.BILINEAR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -341,7 +354,7 @@ namespace NeoLayoutViewer{
|
|||
}
|
||||
|
||||
private bool on_button_pressed (Widget source, Gdk.EventButton event) {
|
||||
if( event.button == 3){
|
||||
if (event.button == 3) {
|
||||
this.hide();
|
||||
}
|
||||
return false;
|
||||
|
@ -355,9 +368,9 @@ namespace NeoLayoutViewer{
|
|||
- “modifier is seleted by mouseclick”
|
||||
as array indizes to eval an new state. See comment of MODIFIER_KEYBOARD_MOUSE_MAP, too.
|
||||
*/
|
||||
public void change_active_modifier(int mod_index, bool keyboard, int new_mod_state){
|
||||
public void change_active_modifier(int mod_index, bool keyboard, int new_mod_state) {
|
||||
int old_mod_state;
|
||||
if( keyboard ){
|
||||
if (keyboard) {
|
||||
//Keypress or Release of shift etc.
|
||||
old_mod_state = this.active_modifier_by_keyboard[mod_index];
|
||||
this.active_modifier_by_keyboard[mod_index] = MODIFIER_KEYBOARD_MOUSE_MAP[
|
||||
|
@ -365,14 +378,14 @@ namespace NeoLayoutViewer{
|
|||
this.active_modifier_by_mouse[mod_index],
|
||||
new_mod_state,
|
||||
this.active_modifier_by_mouse[mod_index]
|
||||
];
|
||||
];
|
||||
this.active_modifier_by_mouse[mod_index] = MODIFIER_KEYBOARD_MOUSE_MAP[
|
||||
this.active_modifier_by_mouse[mod_index],
|
||||
old_mod_state,
|
||||
this.active_modifier_by_mouse[mod_index],
|
||||
new_mod_state
|
||||
];
|
||||
}else{
|
||||
];
|
||||
} else {
|
||||
//Mouseclick on shift button etc.
|
||||
old_mod_state = this.active_modifier_by_mouse[mod_index];
|
||||
this.active_modifier_by_mouse[mod_index] = MODIFIER_KEYBOARD_MOUSE_MAP[
|
||||
|
@ -386,46 +399,46 @@ namespace NeoLayoutViewer{
|
|||
old_mod_state,
|
||||
this.active_modifier_by_keyboard[mod_index],
|
||||
new_mod_state
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getActiveModifierMask(int[] modifier){
|
||||
public int getActiveModifierMask(int[] modifier) {
|
||||
int modMask = 0;
|
||||
foreach( int i in modifier ){
|
||||
modMask += ( this.active_modifier_by_keyboard[i] | this.active_modifier_by_mouse[i] )
|
||||
* this.MODIFIER_MASK[i];
|
||||
foreach (int i in modifier) {
|
||||
modMask += (this.active_modifier_by_keyboard[i] | this.active_modifier_by_mouse[i]) * this.MODIFIER_MASK[i];
|
||||
}
|
||||
return modMask;
|
||||
}
|
||||
|
||||
private void check_modifier(int iet1){
|
||||
private void check_modifier(int iet1) {
|
||||
|
||||
if(iet1 != this.layer){
|
||||
if (iet1 != this.layer) {
|
||||
this.layer = iet1;
|
||||
render_page ();
|
||||
render_page();
|
||||
}
|
||||
}
|
||||
|
||||
public void redraw(){
|
||||
public void redraw() {
|
||||
var tlayer = this.layer;
|
||||
this.layer = this.MODIFIER_MAP2[
|
||||
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[3] | this.active_modifier_by_mouse[3] //neo-mod4
|
||||
] + 1;
|
||||
] + 1;
|
||||
|
||||
// check, which extra modifier is pressed and update.
|
||||
foreach( var modkey in modifier_key_images ){
|
||||
foreach (var modkey in modifier_key_images) {
|
||||
modkey.change(
|
||||
this.active_modifier_by_keyboard[modkey.modifier_index] |
|
||||
this.active_modifier_by_mouse[modkey.modifier_index]
|
||||
);
|
||||
}
|
||||
|
||||
if( tlayer != this.layer)
|
||||
if (tlayer != this.layer) {
|
||||
render_page();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -434,32 +447,34 @@ namespace NeoLayoutViewer{
|
|||
this.image.set_from_pixbuf(this.image_buffer[this.layer]);
|
||||
}
|
||||
|
||||
public Gdk.Pixbuf getIcon(){
|
||||
public Gdk.Pixbuf getIcon() {
|
||||
return this.image_buffer[0];
|
||||
}
|
||||
|
||||
public void external_key_press(int iet1, int modifier_mask){
|
||||
for(int iet2=0; iet2<4; iet2++){
|
||||
if(this.NEO_MODIFIER_MASK[iet2]==modifier_mask){
|
||||
iet1 = this.MODIFIER_MAP[iet1,iet2]+1;
|
||||
public void external_key_press(int iet1, int modifier_mask) {
|
||||
|
||||
for (int iet2 = 0; iet2 < 4; iet2++) {
|
||||
if (this.NEO_MODIFIER_MASK[iet2] == modifier_mask) {
|
||||
iet1 = this.MODIFIER_MAP[iet1, iet2] + 1;
|
||||
this.check_modifier(iet1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
iet1 = this.MODIFIER_MAP[iet1,0]+1;
|
||||
|
||||
iet1 = this.MODIFIER_MAP[iet1, 0] + 1;
|
||||
this.check_modifier(iet1);
|
||||
}
|
||||
|
||||
public void external_key_release(int iet1, int modifier_mask){
|
||||
for(int iet2=0; iet2<4; iet2++){
|
||||
if(this.NEO_MODIFIER_MASK[iet2]==modifier_mask){
|
||||
iet1 = this.MODIFIER_MAP_RELEASE[iet1,iet2]+1;
|
||||
public void external_key_release(int iet1, int modifier_mask) {
|
||||
for (int iet2 = 0; iet2 < 4; iet2++) {
|
||||
if (this.NEO_MODIFIER_MASK[iet2] == modifier_mask) {
|
||||
iet1 = this.MODIFIER_MAP_RELEASE[iet1, iet2] + 1;
|
||||
this.check_modifier(iet1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
iet1 = this.MODIFIER_MAP_RELEASE[iet1,0]+1;
|
||||
iet1 = this.MODIFIER_MAP_RELEASE[iet1, 0] + 1;
|
||||
this.check_modifier(iet1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using Gtk;
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
public class AppStatusIcon {
|
||||
|
||||
public StatusIcon trayicon;
|
||||
private Gtk.Menu menuMain;
|
||||
private NeoWindow neo_win;
|
||||
|
@ -10,8 +11,6 @@ namespace NeoLayoutViewer{
|
|||
public AppStatusIcon(NeoWindow neo_win) {
|
||||
this.neo_win = neo_win;
|
||||
/* Create tray icon */
|
||||
//trayicon = new StatusIcon.from_stock(Stock.HOME);
|
||||
//trayicon = new StatusIcon.from_file("Neo-Icon.png");
|
||||
trayicon = new StatusIcon.from_pixbuf(neo_win.get_icon());
|
||||
trayicon.set_tooltip_text ("Neo 2.0 Layout Viewer");
|
||||
trayicon.set_visible(true);
|
||||
|
@ -21,7 +20,6 @@ namespace NeoLayoutViewer{
|
|||
trayicon.popup_menu.connect(menuMain_popup);
|
||||
|
||||
/* Connect main window with left click/acitvation */
|
||||
//trayicon.activate.connect(this.neo_win.show_all);
|
||||
trayicon.activate.connect(()=>{this.neo_win.toggle();});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,27 +1,28 @@
|
|||
using Gtk;
|
||||
using Unique;
|
||||
|
||||
namespace NeoLayoutViewer{
|
||||
namespace NeoLayoutViewer {
|
||||
|
||||
public const int SHOW=1000;
|
||||
|
||||
public static Unique.App? showPreviousInstance(string name, Gtk.Window win){
|
||||
public static Unique.App? showPreviousInstance(string name, Gtk.Window win) {
|
||||
var app = new Unique.App(name, null);
|
||||
app.add_command ("Show application", SHOW);
|
||||
if( app.is_running ){
|
||||
|
||||
if (app.is_running) {
|
||||
//where is already a running instance
|
||||
debug("Application already running. Show window.");
|
||||
app.send_message(SHOW,null);
|
||||
return null;
|
||||
}
|
||||
|
||||
app.message_received.connect( (t, command, data, time) =>{
|
||||
if(command == SHOW)
|
||||
app.message_received.connect((t, command, data, time) =>{
|
||||
if (command == SHOW) {
|
||||
win.show();
|
||||
}
|
||||
return Unique.Response.OK;
|
||||
});
|
||||
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue