Merge branch 'master' into refactoring

Conflicts:
	src/config-manager.vala
	src/main.vala
	src/neo-window.vala
	src/unique.vala
This commit is contained in:
Olaf Schulz 2013-12-09 14:26:02 +01:00
commit 68b1d82a21
7 changed files with 198 additions and 91 deletions

View File

@ -8,17 +8,29 @@ ICON = indicator
# Build type. Possible values:
# debug, release
BUILDTYPE = debug
BUILDTYPE = release
PROGRAM = neo_layout_viewer
BINNAME = neo_layout_viewer
BINDIR = bin
# Path prefix for 'make install'
PREFIX = /usr/local
APPNAME = NeoLayoutViewer
#########################################################
EXEC_PREFIX = $(PREFIX)
DATADIR = $(PREFIX)/share
VALAC = valac --thread --Xcc="-lm" --Xcc="-DXK_TECHNICAL" --Xcc="-DXK_PUBLISHING" --Xcc="-DXK_APL" -D $(ICON)
VAPIDIR = --vapidir=vapi/
# source files
# Source files
SRC = src/main.vala src/unique.vala src/neo-window.vala src/key-overlay.vala src/config-manager.vala src/keybinding-manager.vala csrc/keysend.c csrc/checkModifier.c
# Asset files
ASSET_FILES=$(wildcard assets/**/*.png)
#test for valac version, workaround for Arch Linux bug
ifeq ($(wildcard /usr/include/gee-0.8),)
GEEVERSION=1.0
@ -39,43 +51,54 @@ PKGS += --pkg appindicator3-0.1
endif
# compiler options for a debug build
#VALAC_DEBUG_OPTS = -g --save-temps
VALAC_DEBUG_OPTS = -g
VALAC_DEBUG_OPTS = -g --save-temps
#VALAC_DEBUG_OPTS = -g
# compiler options for a debug build
VALAC_RELEASE_OPTS = -X -O2 --disable-assert
# the 'all' target build a debug build
all: $(BINDIR) info bulid_debug
all: $(BINDIR) info bulid_$(BUILDTYPE)
# the 'release' target builds a release build
# you might want disable asserts also
release: $(BINDIR) clean bulid_release
info:
@echo ""
@echo "Buildtype: $(BUILDTYPE)"
@echo "Trayicon: $(ICON)"
@echo ""
@echo "Edit the variable ICON in the header of the Makefile"
@echo "Notes:"
@echo "Edit the variable ICON in the head of Makefile"
@echo "if you want enable a tray icon."
@echo ""
@echo "Edit the variabe BUILDTYPE in the header of the Makefile"
@echo "Edit the variabe BUILDTYPE in the head of Makefile"
@echo "to switch build type to 'release'."
@echo ""
@echo ""
# the 'release' target builds a release build
# you might want to disabled asserts also
release: $(BINDIR) clean bulid_$(BUILDTYPE)
$(BINDIR):
mkdir -p $(BINDIR)
ln -s ../assets bin/assets
@mkdir -p $(BINDIR)
@ln -s ../assets bin/assets
bulid_debug:
# @echo $(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o $(BINDIR)/$(PROGRAM) $(PKGS) $(CC_INCLUDES)
@$(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o $(BINDIR)/$(PROGRAM) $(PKGS) $(CC_INCLUDES)
# @echo $(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o $(BINDIR)/$(BINNAME) $(PKGS) $(CC_INCLUDES)
$(VALAC) $(VAPIDIR) $(VALAC_DEBUG_OPTS) $(SRC) -o $(BINDIR)/$(BINNAME) $(PKGS) $(CC_INCLUDES)
bulid_release:
@$(VALAC) $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) -o $(BINDIR)/$(PROGRAM) $(PKGS) $(CC_INCLUDES)
# clean all built files
$(VALAC) $(VAPIDIR) $(VALAC_RELEASE_OPTS) $(SRC) -o $(BINDIR)/$(BINNAME) $(PKGS) $(CC_INCLUDES)
install: all
install -d $(EXEC_PREFIX)/bin
install -D -m 0755 $(BINDIR)/$(BINNAME) $(EXEC_PREFIX)/bin
$(foreach ASSET_FILE,$(ASSET_FILES), install -D -m 0644 $(ASSET_FILE) $(DATADIR)/$(APPNAME)/$(ASSET_FILE) ; )
uninstall:
@rm -v $(EXEC_PREFIX)/bin/$(BINNAME)
@rm -v -r $(DATADIR)/$(APPNAME)
# clean all build files
clean:
@rm -v -fr *~ *.c src/*.c src/*~

View File

@ -1,49 +1,62 @@
Beschreibung
Beschreibung
========================================================================
Der NeoLayoutViewer bietet eine einfache Möglichkeit, das NEO2-
Tastaturlayout¹ auf dem Bildschirm anzuzeigen.
Tastaturlayout¹ auf dem Bildschirm anzuzeigen.
Eine Ebene wird angezeigt, sobald eine der zugehörigen Mod-Tasten
gedrückt wird. Dabei kann auch wenn ein anderes Fenster
selektiert sein.
Das Programmfenster besteht nur aus einem Bild einer der sechs Ebenen des Layouts.
Wird eine der Mod-Tasten (Shift,…) gedrückt oder losgelassen, wechselt die Anzeige zur zugehörigen
Ebene. Außerdem kann das Fenster per Tastenkombination bewegt oder ausgeblendet werden.
Alle Einstellungen können über eine Konfigurationsdatei angepasst werden.
Autoren: Olaf Schulz 2011, rixx 2013
Lizenz: GPLv3
Kompilieren / Installation
Kompilation & Installation
========================================================================
Das Programm kann nur kompiliert werden, wenn Vala (mind. Version 0.16) und einige Header
installiert sind. Installation der Abhängigkeiten unter Ubuntu (12.04, Stand September 2013):
Das Programm benötigt den Kompiler der Programmiersprache Vala (mind. Version 0.16)
und die Developer-Pakete einiger Bibliotheken. Die Abhängigkeiten können unter Ubuntu
mit dem folgenden Befehl nachinstalliert werden, sofern sie nicht bereits vorhanden sind (Stand: Ubuntu 12.04, September 2013). Bei anderen Distributionen muss der Befehl ggf. angepasst werden.
sudo apt-get install valac libgee-dev libgtk-3-dev libx11-dev libunique-3.0-dev libappindicator3-dev
Mittels
Danach zum Kompilieren in einem Terminal
make; sudo make install
make
eingeben. Nach erfolgreicher Kompilierung liegen die Programmdaten
im Unterverzeichnis `bin/`.
kann das Programm kompiliert und unter /usr/local installiert werden.
Unter Gnome 2.x wird eine andere Bibliothek für die Anzeige des Tray-Icons benötigt.
Geben Sie in diesem Falle „make ICON=tray“ ein.
Hinweise
========================================================================
- Beim ersten Start wird die Datei neo_layout_viewer.conf erstellt. (Im
Verzeichnis, in dem der Befehl ausgeführt wird.) In ihr
können einige Einstellungen definiert werden. Unter anderem
- Tastenkürzel für Anzeige und Bewegung des Fensters,
- Breite des Fensters und
- Anzeige des Numblocks/der Funktionstasten.
• Beim ersten Start wird die Datei $HOME/.config/.neo_layout_viewer.conf erstellt.
Sollte die Datei in diesem Verzeichnis nicht angewegt werden können, wird $HOME
und das derzeitge Verzeichnis ausprobiert.
In der Konfigurationsdatei können unter anderem folgende Einstellungen vorgenommen
werden:
- Breite des Fensters. Mit „width“ können Sie die exakte Breite einstellen und mit
„max_width“ und „min_width“ die relative Breite in Bezug auf die derzeitge Auflösung.
- Anzeige des Numblocks und der Funktionstasten.
- Tastenkürzel für Anzeige und Bewegung des Fensters. Möchten Sie die Tasten-
kombination nicht nutzen, löschen Sie den Text hinter dem Gleichheitszeichen.
In den Standardeinstellungen kann das Programmfenster mittels Strg+Alt+N an
acht verschiedenen Positionen verschoben werden. Wenn nur eine Teilmenge dieser
Positionen genutzt werden soll, kann „position_cycle“ angepasst werden.
Der Wert X∈{1,…,9} ist entsprechend der Position auf dem Numblocks zu interpretieren.
Beim Druck der Tastenkombinationen springt das Fenster von Position X zu position_cycle[X].
• Das Programm zeigt unter Gnome 3.x in der Indicator-Leiste ein Symbol an. Unter Gnome 2.x
war für diese Funktion noch eine andere Bibliothek verantwortlich. Sie können im
Makefile zwischen den beiden Varianten wechseln, indem Sie die Variable ICON anpassen.
- Das Programm kann auch ein Trayicon anzeigen. Dazu muss im Makefile
die Option "ICON" geändert werden.
______________________________________________________________________
¹NEO ist eine Tastaturbelegung, welche für die deutsche Sprache optimiert ist.
¹NEO ist eine Tastaturbelegung, welche für die deutsche Sprache optimiert ist.
Die offizielle Seite des Projektes: http://neo-layout.org/

View File

@ -4,9 +4,9 @@ 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) {
public ConfigManager(string[] paths, string conffile) {
this.config = new Gee.TreeMap<string, string>();
this.description = new Gee.TreeMap<string, string>();
@ -16,14 +16,33 @@ namespace NeoLayoutViewer {
//no, it's better to create the conffile in the current dir.
//var conffile2 = @"$(path)$(conffile)";
if (!search_config_file(conffile)) {
create_conf_file(conffile);
} else {
load_config_file(conffile);
//try to read/create config file on given array of paths
string conffile2 = null;
//1. Try to read conf file
foreach( var path in paths ){
string testfile = @"$(path)/$(conffile)";
if( search_config_file(conffile) ){
conffile2 = testfile;
break;
}
}
//add path
config.set("path", path);
//2. Try to write new conf file if read fails
if( conffile2 == null ){
foreach( var path in paths ){
string testfile = @"$(path)/$(conffile)";
if( create_conf_file(testfile) > -1){
conffile2 = testfile;
break;
}
}
}
debug(@"Config file: $(conffile2)");
if(search_config_file(conffile2))
load_config_file(conffile2);
add_intern_values();
}
@ -41,26 +60,27 @@ namespace NeoLayoutViewer {
}
/*
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.
*/
Standard values. This vaules will be written in the config file if
config file was not found.
*/
public void add_defaults(){
addSetting("show_shortcut","<Ctrl><Alt>q", "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("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","<Ctrl><Alt>N", "Circle the window posisition");
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("move_shortcut","<Ctrl><Alt>N", "Circle through window posisitions.");
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# To limit the used positions to screen corners use\n#position_cycle = 3 3 9 1 3 9 1 7 7");
addSetting("display_numpad","1", null);
addSetting("display_function_keys","0", null);
addSetting("window_selectable","0","To use the keyboard window as virtual keyboard, disable this entry.");
addSetting("window_decoration","0","Show window decoration/border. Not recommended.");
addSetting("window_selectable","0","To use the keyboard window as virtual keyboard, disable this entry (option is out of use).");
addSetting("window_decoration","0","Show window decoration/border (not recommended).");
addSetting("screen_width","auto", "Set the resolution of your screen manually, if the automatic detection fails.");
addSetting("screen_height","auto", "Set the resolution of your screen manually, if the automatic detection fails.");
addSetting("show_on_startup","1", "Show window on startup.");
addSetting("asset_folder","./assets", "Default lookup folder image data.");
}
/*
@ -69,7 +89,7 @@ namespace NeoLayoutViewer {
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);
@ -89,7 +109,7 @@ namespace NeoLayoutViewer {
return -1;
}
// Write text data to file
// Write text data to file
var data_stream = new DataOutputStream(file_stream);
foreach (Gee.Map.Entry<string, string> e in this.config.entries) {
@ -100,9 +120,9 @@ namespace NeoLayoutViewer {
data_stream.put_string(e.key + " = " + e.value + "\n");
}
} // Streams
catch (GLib.IOError e) { return -1; }
catch (GLib.Error e) { return -1; }
} // Streams
catch ( GLib.IOError e){ return -1; }
catch ( GLib.Error e){ return -1; }
return 0;
}
@ -127,9 +147,8 @@ namespace NeoLayoutViewer {
if (comment.match(line)) continue;
split = regex.split(line);
if (split.length > 1) {
this.config.set(split[0], split[1]);
if(split.length>1){
this.config.set(split[0].strip(),split[1].strip());
}
}
} catch (GLib.IOError e) {

View File

@ -745,7 +745,7 @@ namespace NeoLayoutViewer {
});
// Image of pressed Button
Gdk.Pixbuf image_buffer = winMain.open_image_str(@"assets/neo2.0/$(pressed_key_image)");
Gdk.Pixbuf image_buffer = winMain.open_image_str(@"$(winMain.config.get("asset_folder"))/neo2.0/$(pressed_key_image)");
var w = image_buffer.width;
var h = image_buffer.height;
image_buffer = image_buffer.scale_simple(width, h*width/w,Gdk.InterpType.BILINEAR);

View File

@ -36,7 +36,28 @@ namespace NeoLayoutViewer{
}
debug(@"Path: $path");
configm = new ConfigManager(path,"neo_layout_viewer.conf");
string[] paths = {
GLib.Environment.get_user_config_dir(),
GLib.Environment.get_home_dir(),
GLib.Environment.get_current_dir()
};
configm = new ConfigManager(paths,".neo_layout_viewer.conf");
// Try to find asset folder (images)
string asset_folder = search_asset_folder( configm.getConfig().get("asset_folder") );
if( asset_folder == null ){
stdout.printf("Application start failed. Asset folder was not found.\n");
stdout.flush();
return 0;
}
//add path to asset folder
configm.getConfig().set("asset_folder",asset_folder);
debug(@"Asset folder: $(asset_folder)\n");
neo_win = new NeoWindow (slayer, configm.getConfig());
var app = showPreviousInstance("org.gnome.neo_layout_viewer", neo_win);
@ -70,7 +91,7 @@ namespace NeoLayoutViewer{
tray menu or indicator menu */
private static void about_dialog() {
var about = new Gtk.AboutDialog();
about.set_version("0.8");
about.set_version("0.9");
about.set_program_name("Neo2.0 Ebenenanzeige");
about.set_comments(@"Erleichtert das Nachschlagen von Tastenkombinationen im Neo 2.0-Layout.\n\n Olaf Schulz\n funwithkinect-AT-googlemail.com\n\n\nTastenkombinationen:\n Ein-/Ausblenden - $(neo_win.config.get("show_shortcut"))\n Bewegen - $(neo_win.config.get("move_shortcut"))\n Beenden (sofern Fenster selektiert) - q\n");
about.set_copyright("GPLv3");
@ -78,6 +99,27 @@ namespace NeoLayoutViewer{
about.hide();
}
/* Check given path and shared files folders for the asset folder.
The folder will be assumed as right one if one required file was found.
@return: assed folder or null.
*/
private static string? search_asset_folder(string path){
string filename = "/icons/Neo-Icon.png";
var file = File.new_for_path (path+filename);
if( file.query_exists(null)) return path;
//string[] datadirs = GLib.Environment.get_system_data_dirs();
var datadirs = GLib.Environment.get_system_data_dirs();
foreach( var s in datadirs ){
var path2 = s+"NeoLayoutViewer/assets";
var file2 = File.new_for_path (path2+filename);
if( file2.query_exists(null)) return path2;
}
return null;
}
}
/* Extern C routines */

View File

@ -152,7 +152,7 @@ namespace NeoLayoutViewer {
this.status = new Label("");
status.show();
int width;
int width;
int height;
this.get_size2(out width, out height);
@ -194,16 +194,21 @@ namespace NeoLayoutViewer {
}
this.show();
if( this.config.get("show_on_startup") != "0" ){
//Move ist erst nach show() erfolgreich
this.show();
this.numkeypad_move(int.parse(config.get("position")));
}else{
this.hide();
this.numkeypad_move(int.parse(config.get("position")));
}
//Move ist erst nach show() erfolgreich
this.numkeypad_move(int.parse(config.get("position")));
}
public override void show() {
this.minimized = false;
this.move(this.position_on_hide_x,this.position_on_hide_y);
base.show();
this.move(this.position_on_hide_x, this.position_on_hide_y);
if (config.get("on_top") == "1") {
this.set_keep_above(true);
@ -286,11 +291,17 @@ namespace NeoLayoutViewer {
}
this.position_num = pos;
this.move(x, y);
//store current coordinates
this.position_on_hide_x = x;
this.position_on_hide_y = y;
this.move(x,y);
}
public Gdk.Pixbuf open_image(int layer) {
var bildpfad = "assets/neo2.0/tastatur_neo_Ebene%i.png".printf(layer);
public Gdk.Pixbuf open_image (int layer) {
var bildpfad = @"$(config.get("asset_folder"))/neo2.0/tastatur_neo_Ebene$(layer).png";
return open_image_str(bildpfad);
}
@ -304,7 +315,7 @@ namespace NeoLayoutViewer {
public void load_image_buffer () {
this.image_buffer = new Gdk.Pixbuf[7];
this.image_buffer[0] = open_image_str(@"$(this.config.get("path"))assets/icons/Neo-Icon.png");
this.image_buffer[0] = open_image_str(@"$(config.get("asset_folder"))/icons/Neo-Icon.png");
int screen_width = Gdk.Screen.width();
int max_width = (int) (double.parse(this.config.get("max_width")) * screen_width);

View File

@ -3,25 +3,24 @@ using Unique;
namespace NeoLayoutViewer {
public const int SHOW=1000;
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) {
app.add_command ("Show application", SHOW);
if( app.is_running ){
//where is already a running instance
debug("Application already running. Show window.");
debug("Application already running. Show window of other instance.");
app.send_message(SHOW,null);
return null;
}
app.message_received.connect((t, command, data, time) =>{
if (command == SHOW) {
win.show();
}
return Unique.Response.OK;
});
app.message_received.connect( (t, command, data, time) =>{
if(command == SHOW){
((NeoWindow)win).toggle();
}
return Unique.Response.OK;
});
return app;
}