Permalink
Browse files

Limit number of application instances to one. Show first application …

…window, if second instance is started.
  • Loading branch information...
YggdrasiI committed Oct 23, 2011
1 parent ee96bb8 commit 64620df6928efc404eeca84bd8b7aa2c681a0c73
Showing with 58 additions and 4 deletions.
  1. +2 −2 Makefile
  2. +1 −1 README
  3. +7 −1 src/key-overlay.vala
  4. +9 −0 src/main.vala
  5. +9 −0 src/neo-window.vala
  6. +30 −0 src/unique.vala
View
@@ -8,10 +8,10 @@ BINDIR = bin
# for most cases the following two are the only you'll need to change
# add your source files here
-SRC = src/main.vala src/neo-window.vala src/key-overlay.vala src/tray.vala src/config-manager.vala src/keybinding-manager.vala csrc/keysend.c csrc/checkModifier.c
+SRC = src/main.vala src/unique.vala src/neo-window.vala src/key-overlay.vala src/tray.vala src/config-manager.vala src/keybinding-manager.vala csrc/keysend.c csrc/checkModifier.c
# add your used packges here
-PKGS = --pkg x11 --pkg keysym --pkg gtk+-2.0 --pkg gee-1.0 --pkg gdk-x11-2.0 --pkg posix
+PKGS = --pkg x11 --pkg keysym --pkg gtk+-2.0 --pkg gee-1.0 --pkg gdk-x11-2.0 --pkg posix --pkg unique-1.0
#PKGS = --pkg keysym --pkg x11 --pkg gtk+-2.0 --pkg gee-1.0 --pkg gdk-x11-2.0 --pkg posix
#CC_INCLUDES =
View
2 README
@@ -31,7 +31,7 @@ KOMPILIEREN / INSTALLATION
Das Programm kann nur kompiliert wenden, wenn Vala installiert ist
und ein paar Header installiert sind.
Unter Ubuntu:
- sudo apt-get install valac libgee-dev libgtk2.0-dev libx11-dev
+ sudo apt-get install valac libgee-dev libgtk2.0-dev libx11-dev libunique-dev
Damit für (fast) alle Symbole des Layouts Konstanten definiert werden,
müssen die folgenden Zeilen in der Datei /usr/include/X11/keysym.h
View
@@ -42,6 +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. */
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*/ }));
@@ -659,7 +660,8 @@ namespace NeoLayoutViewer{
Die Reihenfolge der Zeichen in keysyms passt nicht
zur Nummerierung der Ebenen in winMain. Mit diesem Array
wird der Wert permutiert.
- Achtung, mittlerweile ist es die Identitätsabbildung.
+ Achtung, mittlerweile ist es die Identitätsabbildung, da die zwei
+ redundanten Layer, die durch Caps-Lock entstehen, entfernt wurden.
*/
private static const short[] layer_permutation = {0,1,2,3,5,4,6};
@@ -688,6 +690,10 @@ namespace NeoLayoutViewer{
//GLib.stdout.printf("Ww: %i, Wh: %i\n", width, height);
this.button_press_event.connect ((event) => {
+ if( event.button != 1){
+ return false;
+ }
+
uint ks = this.keysym[this.layer_permutation[winMain.layer]-1];
int modi = winMain.getActiveModifierMask({4,5}); //ctrl+alt mask
//debug(@"Modi: $modi");
View
@@ -8,6 +8,7 @@ namespace NeoLayoutViewer{
public ConfigManager configm;
public static int main (string[] args) {
+
string slayer;
if( args.length<2) {
slayer="1";
@@ -17,6 +18,7 @@ namespace NeoLayoutViewer{
Gtk.init (ref args);
+
//Get program path (no binding for getcwd found…)
string path = "";
try {
@@ -30,6 +32,12 @@ namespace NeoLayoutViewer{
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;
+ }
+
neo_tray = new AppStatusIcon(neo_win);
manager = new KeybindingManager(neo_win);
@@ -47,6 +55,7 @@ namespace NeoLayoutViewer{
}
+
}
/* Extern C routines */
View
@@ -180,6 +180,7 @@ namespace NeoLayoutViewer{
//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.set_gravity(Gdk.Gravity.SOUTH);
@@ -423,6 +424,14 @@ namespace NeoLayoutViewer{
return false;
}
+ private bool on_button_pressed (Widget source, Gdk.EventButton event) {
+ //debug(@"Hide event. Button: $(event.button)");
+ if( event.button == 3){
+ this.hide();
+ }
+ return false;
+ }
+
/*
Use the for values
- “modifier was pressed”
View
@@ -0,0 +1,30 @@
+using Gtk;
+using Unique;
+
+namespace NeoLayoutViewer{
+
+public const int SHOW=1000;
+
+public static Unique.App? showPreviousInstance(string name, Gtk.Window win){
+ //unique_app_send_message ()
+ var app = new Unique.App(name, null);
+ app.add_command ("Show application", SHOW);
+ 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)
+ win.show();
+ return Unique.Response.OK;
+ });
+
+
+ return app;
+ }
+
+}
+

0 comments on commit 64620df

Please sign in to comment.