-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] a floating window widget for Variety #87
Open
jlu5
wants to merge
10
commits into
master
Choose a base branch
from
floating-window
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
59800ea
Remove OnlyShowIn=Unity from desktop entries
jlu5 9ca12c1
WIP: add a mini floating window that will eventually pop up the Varie…
jlu5 f3b961e
Integrate FloatingWindow with the Variety app
jlu5 e04cae3
FloatingWindow: disable window decorations
jlu5 d641c83
Run --floating instead of --preferences by default if Variety is alre…
jlu5 4419b38
Refactor: pass the entire VarietyWindow instance to FloatingWindow
jlu5 6be7b45
VarietyWindow: split scroll handling into a function that only takes …
jlu5 2e3a8ad
FloatingWindow: change the wallpaper on mouse scroll
jlu5 ea14d74
FloatingWindow: Don't disable decorations on Wayland
jlu5 16751c0
Revert "Run --floating instead of --preferences by default if Variety…
jlu5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import gi | ||
import cairo | ||
|
||
gi.require_version('Gtk', '3.0') | ||
|
||
from gi.repository import Gtk, Gdk, GObject | ||
|
||
class FloatingWindow(Gtk.Window): | ||
__gtype_name__ = "FloatingWindow" | ||
|
||
def __init__(self, parent=None): | ||
super().__init__() | ||
|
||
self.running = True | ||
self.parent = parent | ||
|
||
if os.environ.get('XDG_SESSION_TYPE') != 'wayland': # Movement tracking doesn't work on Wayland :( | ||
self.set_decorated(False) | ||
self.set_accept_focus(True) | ||
self.set_title('Variety') | ||
self.set_resizable(False) | ||
self.set_default_size(48, 48) | ||
|
||
self.connect('draw', self.draw) | ||
|
||
# Try rgba mode if compositing is on | ||
screen = self.get_screen() | ||
visual = screen.get_rgba_visual() | ||
if visual and screen.is_composited(): | ||
self.set_visual(visual) | ||
self.set_opacity(0.8) | ||
|
||
self.set_app_paintable(True) | ||
|
||
self._eventbox = Gtk.EventBox() | ||
self._eventbox.set_visible(True) | ||
|
||
# Handle button press & left mouse button | ||
self._eventbox.set_events(Gdk.EventMask.BUTTON_PRESS_MASK | | ||
Gdk.EventMask.BUTTON1_MOTION_MASK | | ||
Gdk.EventMask.SCROLL_MASK) | ||
self._eventbox.connect('motion-notify-event', self.handle_drag) | ||
self._eventbox.connect('button-press-event', self.handle_click) | ||
self._eventbox.connect('scroll-event', self.handle_scroll) | ||
|
||
self._image = Gtk.Image.new_from_icon_name("variety", Gtk.IconSize.DIALOG) | ||
self._eventbox.add(self._image) | ||
|
||
self.add(self._eventbox) | ||
self.show_all() | ||
|
||
self._last_offset = None | ||
|
||
def draw(self, widget, context): | ||
""" | ||
Draws the window with transparent window background. | ||
""" | ||
# Based off https://gist.github.com/KurtJacobson/374c8cb83aee4851d39981b9c7e2c22c | ||
context.set_source_rgba(0, 0, 0, 0) | ||
context.set_operator(cairo.OPERATOR_SOURCE) | ||
context.paint() | ||
context.set_operator(cairo.OPERATOR_OVER) | ||
|
||
def handle_click(self, widget, event, data=None): | ||
""" | ||
Handles mouse click: | ||
|
||
1) Find the offset from the cursor to the widget to assist with dragging. | ||
We want to allow dragging in the way that the cursor is at the same position | ||
relative to the window when the window moves (instead of moving with the cursor | ||
always at the top left). | ||
2) Bring up the Variety Menu when right-clicked or double-clicked. | ||
""" | ||
self._last_offset = (event.x, event.y) | ||
|
||
if event.button != 1 or event.type == Gdk.EventType._2BUTTON_PRESS: | ||
# This program can run as a standalone app too for testing :) | ||
if self.parent: | ||
self.parent.ind.menu.popup_at_pointer(event) | ||
else: | ||
print('Not showing menu; we were started in a standalone fashion.') | ||
|
||
def handle_drag(self, widget, event, data=None): | ||
""" | ||
Handles drag movement when the left mouse button is pressed down. | ||
""" | ||
if self._last_offset: | ||
current_x, current_y = self.get_position() | ||
offset_x, offset_y = self._last_offset | ||
x = current_x + event.x - offset_x | ||
y = current_y + event.y - offset_y | ||
self.move(x, y) | ||
|
||
def handle_scroll(self, widget, event, data=None): | ||
""" | ||
Handles scrolling to change the wallpaper. | ||
""" | ||
if self.parent: | ||
self.parent.handle_scroll(event.direction) | ||
|
||
if __name__ == "__main__": | ||
w = FloatingWindow() | ||
w.show() | ||
Gtk.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we won't see the title anywhere, but probably still makes sense to use a descriptive one for this specific window - e.g. "Variety Control"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title is always shown on GNOME/Wayland since it doesn't seem undecorated windows are able to move themselves.