Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rewritten feature which places gmrun window on monitor

* Removed config option 'Centrize'
* Added three new config options: 'CenteredByWidth', 'CenteredByHeight'
and 'UseActiveMonitor'
  • Loading branch information...
commit f5051553fe764cb16ad575d99b0a27619e00c5cb 1 parent 2b41bc2
Makoto authored May 14, 2012

Showing 1 changed file with 79 additions and 37 deletions. Show diff stats Hide diff stats

  1. 116  src/main.cc
116  src/main.cc
@@ -282,10 +282,10 @@ static void
282 282
 on_compline_runwithterm(GtkCompletionLine *cl, struct gigi* g)
283 283
 {
284 284
   string command(g_locale_from_utf8 (gtk_entry_get_text(GTK_ENTRY(cl)),
285  
-				     -1,
286  
-				     NULL,
287  
-				     NULL,
288  
-				     NULL));
  285
+                     -1,
  286
+                     NULL,
  287
+                     NULL,
  288
+                     NULL));
289 289
   string tmp;
290 290
   string term;
291 291
 
@@ -390,10 +390,10 @@ static bool
390 390
 url_check(GtkCompletionLine *cl, struct gigi *g)
391 391
 {
392 392
   string text(g_locale_from_utf8 (gtk_entry_get_text(GTK_ENTRY(cl)),
393  
-				  -1,
394  
-				  NULL,
395  
-				  NULL,
396  
-				  NULL));
  393
+                  -1,
  394
+                  NULL,
  395
+                  NULL,
  396
+                  NULL));
397 397
 
398 398
   string::size_type i;
399 399
   string::size_type sp;
@@ -492,10 +492,10 @@ on_compline_activated(GtkCompletionLine *cl, struct gigi *g)
492 492
     return;
493 493
 
494 494
   string command = g_locale_from_utf8 (gtk_entry_get_text(GTK_ENTRY(cl)),
495  
-				       -1,
496  
-				       NULL,
497  
-				       NULL,
498  
-				       NULL);
  495
+                       -1,
  496
+                       NULL,
  497
+                       NULL,
  498
+                       NULL);
499 499
 
500 500
   string::size_type i;
501 501
   i = command.find_first_not_of(" \t");
@@ -596,9 +596,13 @@ gmrun_gdk_display_locate_monitor_with_pointer (GdkDisplay *display,
596 596
   Taked from Xfce: libxfcegui4
597 597
  */
598 598
 static void
599  
-gmrun_gtk_window_center_on_monitor (GtkWindow *window,
  599
+//gmrun_gtk_window_center_on_monitor (GtkWindow *window,
  600
+gmrun_gtk_window_place_on_monitor (GtkWindow *window,
600 601
                                    GdkScreen *screen,
601  
-                                   gint       monitor)
  602
+                                   gint       monitor,
  603
+                                   int        request_x = -1,
  604
+                                   int        request_y = -1)
  605
+
602 606
 {
603 607
     GtkRequisition requisition;
604 608
     GdkRectangle   geometry;
@@ -631,30 +635,64 @@ gmrun_gtk_window_center_on_monitor (GtkWindow *window,
631 635
     requisition.width = requisition.height = -1;
632 636
     gtk_widget_size_request (GTK_WIDGET (window), &requisition);
633 637
 
634  
-    x = geometry.x + (geometry.width - requisition.width) / 2;
635  
-    y = geometry.y + (geometry.height - requisition.height - 200) / 2;
  638
+    if( request_x < 0 )
  639
+    {
  640
+        x = geometry.x + (geometry.width - requisition.width) / 2;
  641
+    }
  642
+    else
  643
+    {
  644
+        x = geometry.x + request_x;
  645
+    }
  646
+
  647
+    if( request_y < 0 )
  648
+    {
  649
+        y = geometry.y + (geometry.height - requisition.height - 200) / 2;
  650
+    }
  651
+    else
  652
+    {
  653
+        y = geometry.y + request_y;
  654
+    }
636 655
 
637 656
     gtk_window_move (window, x, y);
638 657
 }
639 658
 
640  
-/**
641  
- Move window to center
642  
- Taked from Xfce: libxfcegui4
643  
- */
644 659
 static void
645  
-gmrun_gtk_window_center_on_monitor_with_pointer (GtkWindow *window)
  660
+gmrun_gtk_window_place_at(GtkWindow *window,
  661
+                        int request_x,
  662
+                        int request_y,
  663
+                        int centered_width = 0,
  664
+                        int centered_height = 0,
  665
+                        int on_active = 0)
646 666
 {
647  
-    GdkScreen *screen;
648  
-    gint       monitor;
  667
+    GdkScreen *screen = NULL;
  668
+    gint       monitor = 0;
649 669
 
650  
-    screen = gmrun_gdk_display_locate_monitor_with_pointer (NULL, &monitor);
651  
-    if (screen == NULL)
  670
+    if(on_active != 0)
652 671
     {
653  
-        screen = gdk_screen_get_default ();
  672
+        screen = gmrun_gdk_display_locate_monitor_with_pointer(NULL, &monitor);
  673
+    }
  674
+
  675
+    if( screen == NULL )
  676
+    {
  677
+        screen = gdk_screen_get_default();
654 678
         monitor = 0;
655 679
     }
656 680
 
657  
-    gmrun_gtk_window_center_on_monitor (window, screen, monitor);
  681
+    if(centered_width != 0)
  682
+    {
  683
+        request_x = -1;
  684
+    }
  685
+
  686
+    if(centered_height != 0)
  687
+    {
  688
+        request_y = -1;
  689
+    }
  690
+
  691
+    gmrun_gtk_window_place_on_monitor(window,
  692
+                                      screen,
  693
+                                      monitor,
  694
+                                      request_x,
  695
+                                      request_y);
658 696
 }
659 697
 
660 698
 int main(int argc, char **argv)
@@ -758,10 +796,14 @@ int main(int argc, char **argv)
758 796
 
759 797
   int prefs_top = 80;
760 798
   int prefs_left = 100;
761  
-  int prefs_centrize = 0;
  799
+  int prefs_centred_by_width = 0;
  800
+  int prefs_centred_by_height = 0;
  801
+  int prefs_use_active_monitor = 0;
762 802
   configuration.get_int("Top", prefs_top);
763 803
   configuration.get_int("Left", prefs_left);
764  
-  configuration.get_int("Centrize", prefs_centrize);
  804
+  configuration.get_int("CenteredByWidth", prefs_centred_by_width);
  805
+  configuration.get_int("CenteredByHeight", prefs_centred_by_height);
  806
+  configuration.get_int("UseActiveMonitor", prefs_use_active_monitor);
765 807
 
766 808
   // parse commandline options
767 809
   gboolean geo_parsed;
@@ -783,19 +825,19 @@ int main(int argc, char **argv)
783 825
   context = poptGetContext("popt1", argc, (const char**) argv, options, 0);
784 826
   option = poptGetNextOpt (context);
785 827
 
786  
-  if (prefs_centrize != 0)
787  
-  {
788  
-      /* Center window on screen */
789  
-      gmrun_gtk_window_center_on_monitor_with_pointer(GTK_WINDOW(win));
790  
-  }
791  
-  else if (strcmp (geoptr, ""))
  828
+  if (strcmp (geoptr, ""))
792 829
   {
793 830
     geo_parsed = gtk_window_parse_geometry (GTK_WINDOW (win),
794  
-					    geoptr);
  831
+                        geoptr);
795 832
   }
796 833
   else
797 834
   {
798  
-    gtk_widget_set_uposition(win, prefs_left, prefs_top);
  835
+      gmrun_gtk_window_place_at(GTK_WINDOW(win),
  836
+                                prefs_left,
  837
+                                prefs_top,
  838
+                                prefs_centred_by_width,
  839
+                                prefs_centred_by_height,
  840
+                                prefs_use_active_monitor);
799 841
   }
800 842
 
801 843
   gtk_widget_show(win);

0 notes on commit f505155

Please sign in to comment.
Something went wrong with that request. Please try again.