Skip to content

Commit

Permalink
Merge pull request #365 from schnittchen/master
Browse files Browse the repository at this point in the history
Refactoring, positioning fix and pushing towards #364
  • Loading branch information
gsemet committed Sep 4, 2014
2 parents a049adb + cce2c84 commit 2f9cf1d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 42 deletions.
13 changes: 0 additions & 13 deletions data/guake.schemas
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<gconfschemafile>
<schemalist>
<schema>
<key>/schemas/apps/guake/general/primary_display</key>
<applyto>/apps/guake/general/primary_display</applyto>
<owner>guake</owner>
<type>bool</type>
<default>true</default>
<locale name="C">
<short>Appear on the primary display.</short>
<long>Appear on the primary display. This overrides any setting
in display_n.</long>
</locale>
</schema>

<schema>
<key>/schemas/apps/guake/general/mouse_display</key>
<applyto>/apps/guake/general/mouse_display</applyto>
Expand Down
4 changes: 3 additions & 1 deletion src/globals.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Boston, MA 02110-1301 USA
__all__ = [
'NAME', 'VERSION', 'IMAGE_DIR', 'GLADE_DIR', 'LOCALE_DIR',
'GCONF_PATH', 'KEY', 'TERMINAL_MATCH_EXPRS', 'TERMINAL_MATCH_TAGS',
'ALIGN_CENTER', 'ALIGN_RIGHT', 'ALIGN_LEFT', 'ALIGN_TOP', 'ALIGN_BOTTOM'
'ALIGN_CENTER', 'ALIGN_RIGHT', 'ALIGN_LEFT', 'ALIGN_TOP', 'ALIGN_BOTTOM',
'ALWAYS_ON_PRIMARY'
]

NAME = 'guake'
Expand Down Expand Up @@ -56,6 +57,7 @@ TERMINAL_MATCH_EXPRS = [
TERMINAL_MATCH_TAGS = 'schema', 'http', 'email'
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT = range(3)
ALIGN_TOP, ALIGN_BOTTOM = range(2)
ALWAYS_ON_PRIMARY = -1

# tuple (title/quick matcher/filename and line number extractor)
QUICK_OPEN_MATCHERS = [
Expand Down
56 changes: 36 additions & 20 deletions src/guake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ from guake.globals import ALIGN_BOTTOM
from guake.globals import ALIGN_CENTER
from guake.globals import ALIGN_LEFT
from guake.globals import ALIGN_RIGHT
from guake.globals import ALWAYS_ON_PRIMARY
from guake.globals import GCONF_PATH
from guake.globals import KEY
from guake.globals import LOCALE_DIR
Expand Down Expand Up @@ -1093,23 +1094,13 @@ class Guake(SimpleGladeApp):
self.window.set_keep_below(True)
self.window.hide() # Don't use hide_all here!

def get_final_window_rect(self):
"""Gets the final size of the main window of guake. The height
is the window_height property, width is window_width and the
horizontal alignment is given by window_alignment.
def get_final_window_monitor(self):
"""Gets the final screen number for the main window of guake.
"""

screen = self.window.get_screen()
try:
height = self.client.get_float(KEY('/general/window_height'))
except:
height = self.client.get_int(KEY('/general/window_height'))
try:
width = self.client.get_float(KEY('/general/window_width'))
except:
width = self.client.get_int(KEY('/general/window_width'))
halignment = self.client.get_int(KEY('/general/window_halignment'))
valignment = self.client.get_int(KEY('/general/window_valignment'))

# fetch settings
use_mouse = self.client.get_bool(KEY('/general/mouse_display'))
dest_screen = self.client.get_int(KEY('/general/display_n'))

Expand All @@ -1125,8 +1116,34 @@ class Guake(SimpleGladeApp):
self.client.set_int(KEY('/general/display_n'), dest_screen)
dest_screen = screen.get_primary_monitor()

# Use primary display if configured
if dest_screen == ALWAYS_ON_PRIMARY:
dest_screen = screen.get_primary_monitor()

return dest_screen

def get_final_window_rect(self):
"""Gets the final size of the main window of guake. The height
is the window_height property, width is window_width and the
horizontal alignment is given by window_alignment.
"""

# fetch settings
try:
height_percents = self.client.get_float(KEY('/general/window_height'))
except:
height_percents = self.client.get_int(KEY('/general/window_height'))
try:
width_percents = self.client.get_float(KEY('/general/window_width'))
except:
width_percents = self.client.get_int(KEY('/general/window_width'))
halignment = self.client.get_int(KEY('/general/window_halignment'))
valignment = self.client.get_int(KEY('/general/window_valignment'))

# get the rectangle just from the destination monitor
window_rect = screen.get_monitor_geometry(dest_screen)
screen = self.window.get_screen()
monitor = self.get_final_window_monitor()
window_rect = screen.get_monitor_geometry(monitor)

if os.environ.get('DESKTOP_SESSION') == "ubuntu":
unity_hide = self.client.get_int(KEY('/apps/compiz-1/plugins/'
Expand All @@ -1144,8 +1161,8 @@ class Guake(SimpleGladeApp):
total_width = window_rect.width
total_height = window_rect.height

window_rect.height = window_rect.height * height / 100
window_rect.width = window_rect.width * width / 100
window_rect.height = window_rect.height * height_percents / 100
window_rect.width = window_rect.width * width_percents / 100

if window_rect.width < total_width:
if halignment == ALIGN_CENTER:
Expand All @@ -1154,10 +1171,9 @@ class Guake(SimpleGladeApp):
window_rect.x += 0
elif halignment == ALIGN_RIGHT:
window_rect.x += total_width - window_rect.width
window_rect.y = 0
if height < total_height:
if window_rect.height < total_height:
if valignment == ALIGN_BOTTOM:
window_rect.y = (total_height - window_rect.height)
window_rect.y += (total_height - window_rect.height)

return window_rect

Expand Down
35 changes: 27 additions & 8 deletions src/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from guake.globals import ALIGN_CENTER
from guake.globals import ALIGN_LEFT
from guake.globals import ALIGN_RIGHT
from guake.globals import ALWAYS_ON_PRIMARY
from guake.globals import GCONF_PATH
from guake.globals import KEY
from guake.globals import LOCALE_DIR
Expand Down Expand Up @@ -264,11 +265,19 @@ def on_bottom_align_toggled(self, chk):
def on_display_n_changed(self, combo):
"""Set the destination display in gconf.
"""

i = combo.get_active_iter()
if not i:
return
val = combo.get_model().get_value(i, 0)
val_int = int(val.split()[0]) # extracts 1 from '1' or from '1 (primary)'

model = combo.get_model()
first_item_path = model.get_path(model.get_iter_first())

if model.get_path(i) == first_item_path:
val_int = ALWAYS_ON_PRIMARY
else:
val = model.get_value(i, 0)
val_int = int(val.split()[0]) # extracts 1 from '1' or from '1 (primary)'
self.client.set_int(KEY('/general/display_n'), val_int)

def on_window_height_value_changed(self, hscale):
Expand Down Expand Up @@ -482,7 +491,7 @@ def toggle_style_sensitivity(self, chk):
self.get_widget('font_style').set_sensitive(not chk.get_active())

def toggle_display_n_sensitivity(self, chk):
"""When the user unchecks 'primary display', the option to select an
"""When the user unchecks 'on mouse display', the option to select an
alternate display should be enabeld.
"""
self.get_widget('display_n').set_sensitive(not chk.get_active())
Expand Down Expand Up @@ -664,10 +673,18 @@ def load_configs(self):
dest_screen = screen.get_primary_monitor()
self.client.set_int(KEY('/general/display_n'), dest_screen)

for i in combo.get_model():
i_int = int(i[0].split()[0]) # extracts 1 from '1' or from '1 (primary)'
if i_int == dest_screen:
combo.set_active_iter(i.iter)
if dest_screen == ALWAYS_ON_PRIMARY:
first_item = combo.get_model().get_iter_first()
combo.set_active_iter(first_item)
else:
seen_first = False # first item "always on primary" is special
for i in combo.get_model():
if seen_first:
i_int = int(i[0].split()[0]) # extracts 1 from '1' or from '1 (primary)'
if i_int == dest_screen:
combo.set_active_iter(i.iter)
else:
seen_first = True

# use display where the mouse is currently
value = self.client.get_bool(KEY('/general/mouse_display'))
Expand Down Expand Up @@ -778,11 +795,13 @@ def populate_keys_tree(self):

def populate_display_n(self):
"""Get the number of displays and populate this drop-down box
with them all.
with them all. Prepend the "always on primary" option.
"""
cb = self.get_widget('display_n')
screen = self.get_widget('config-window').get_screen()

cb.append_text("always on primary")

for m in range(0, int(screen.get_n_monitors())):
if m == int(screen.get_primary_monitor()):
# TODO l10n
Expand Down

0 comments on commit 2f9cf1d

Please sign in to comment.