forked from BlankOn/blankon-panel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mohammad Anwari
committed
Feb 27, 2011
0 parents
commit 5e85cf7
Showing
10 changed files
with
720 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Mohammad Anwari <mdamt@di.blankon.in> |
Large diffs are not rendered by default.
Oops, something went wrong.
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,18 @@ | ||
SOURCES=panel-item.vala \ | ||
main.vala \ | ||
panel-horizontal.vala \ | ||
panel-menu.vala \ | ||
panel-menu-box.vala \ | ||
panel-button.vala \ | ||
panel-clock.vala \ | ||
|
||
LIBS= --pkg cairo --pkg gtk+-3.0 --pkg gio-unix-2.0 --pkg libgnome-menu --pkg gdk-3.0 -X "-DGMENU_I_KNOW_THIS_IS_UNSTABLE" | ||
BIN=blankon-panel | ||
|
||
blankon-panel: | ||
valac -o $(BIN) $(SOURCES) $(LIBS) | ||
|
||
all: blankon-panel | ||
|
||
clean: | ||
rm -f $(BIN) |
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,18 @@ | ||
using Gtk; | ||
|
||
int main (string[] args) { | ||
Gtk.init (ref args); | ||
|
||
|
||
var h = new PanelHorizontal(); | ||
h.destroy.connect (Gtk.main_quit); | ||
|
||
var m = new PanelButtonWindow(); | ||
m.set_transient_for(h); | ||
|
||
m.show_all(); | ||
h.show_all (); | ||
|
||
Gtk.main (); | ||
return 0; | ||
} |
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,182 @@ | ||
using Gtk; | ||
using Cairo; | ||
using GMenu; | ||
|
||
public class PanelButtonWindow : Gtk.Window { | ||
|
||
private ImageSurface surface; | ||
private PanelMenuBox menuBox; | ||
private Gdk.Rectangle rect; | ||
|
||
public PanelButtonWindow() { | ||
set_type_hint (Gdk.WindowTypeHint.DOCK); | ||
add_events (Gdk.EventMask.BUTTON_PRESS_MASK | ||
| Gdk.EventMask.BUTTON_RELEASE_MASK | ||
| Gdk.EventMask.POINTER_MOTION_MASK); | ||
|
||
menuBox = new PanelMenuBox(); | ||
set_visual (this.screen.get_rgba_visual ()); | ||
set_decorated(false); | ||
set_keep_above(true); | ||
stick(); | ||
resizable = false; | ||
|
||
accept_focus = true; | ||
menuBox.set_transient_for(this); | ||
|
||
surface = new ImageSurface.from_png("/home/mdamt/blankon.png"); | ||
set_size_request (surface.get_width(), surface.get_height()); | ||
|
||
Gdk.RGBA c = Gdk.RGBA(); | ||
c.red = 0.0; | ||
c.blue = 0.0; | ||
c.green = 0.0; | ||
c.alpha = 0.0; | ||
override_background_color(StateFlags.NORMAL, c); | ||
set_app_paintable(true); | ||
|
||
var screen = get_screen(); | ||
screen.get_monitor_geometry (screen.get_primary_monitor(), out rect); | ||
move (rect.x, rect.y); | ||
} | ||
|
||
public override bool draw (Context cr) | ||
{ | ||
cr.set_source_surface(surface, 0, 0); | ||
cr.paint(); | ||
return false; | ||
} | ||
|
||
public override bool button_press_event (Gdk.EventButton event) { | ||
if (menuBox.get_visible ()) { | ||
menuBox.hide(); | ||
} else { | ||
menuBox.show(); | ||
} | ||
return false; | ||
} | ||
|
||
public override bool button_release_event (Gdk.EventButton event) { | ||
//this.menu.activate(); | ||
return false; | ||
} | ||
|
||
|
||
} | ||
|
||
public class xPanelButton : DrawingArea { | ||
private PanelMenu menu; | ||
private ImageSurface surface; | ||
|
||
public xPanelButton () { | ||
add_events (Gdk.EventMask.BUTTON_PRESS_MASK | ||
| Gdk.EventMask.BUTTON_RELEASE_MASK | ||
| Gdk.EventMask.POINTER_MOTION_MASK); | ||
|
||
surface = new ImageSurface.from_png("/home/mdamt/blankon.png"); | ||
set_size_request (surface.get_width(), surface.get_height()); | ||
|
||
Gdk.RGBA c = Gdk.RGBA(); | ||
c.red = 0.0; | ||
c.blue = 0.0; | ||
c.green = 0.0; | ||
c.alpha = 0.0; | ||
override_background_color(StateFlags.NORMAL, c); | ||
set_app_paintable(true); | ||
|
||
menu = new PanelMenu(); | ||
//menu.update_content(); | ||
} | ||
|
||
public override bool draw (Context cr) | ||
{ | ||
cr.set_source_surface(surface, 0, 0); | ||
cr.paint(); | ||
return false; | ||
} | ||
|
||
public override bool button_press_event (Gdk.EventButton event) { | ||
//this.menu.activate(); | ||
return false; | ||
} | ||
|
||
public override bool button_release_event (Gdk.EventButton event) { | ||
//this.menu.activate(); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
public class xPanelMenu : Menu { | ||
|
||
public void f(Menu m, out int x, out int y, out bool push_in) | ||
{ | ||
int xx, yy; | ||
get_attach_widget().get_window().get_position(out xx, out yy); | ||
stdout.printf (">: %d %d\n", xx, yy); | ||
x = xx; | ||
y = yy; | ||
} | ||
|
||
public new void activate() { | ||
select_first(false); | ||
popup(null, null, f, 0, 0); | ||
} | ||
|
||
public void update_content () { | ||
List<GMenu.TreeDirectory> directories = get_main_directories(); | ||
|
||
foreach (GMenu.TreeDirectory item in directories) { | ||
var menu_item = new ImageMenuItem.with_label(item.get_name()); | ||
stdout.printf (">: %s\n", item.get_icon()); | ||
menu_item.set_image(new Image.from_icon_name (item.get_icon(), IconSize.MENU)); | ||
append (menu_item); | ||
} | ||
} | ||
|
||
List<GMenu.TreeDirectory> get_main_directories () { | ||
var tree = GMenu.Tree.lookup ("applications.menu", GMenu.TreeFlags.SHOW_EMPTY); | ||
var root = tree.get_root_directory (); | ||
|
||
var dirs = new List<GMenu.TreeDirectory> (); | ||
|
||
foreach (GMenu.TreeItem item in root.get_contents ()) { | ||
if (item.get_type () == GMenu.TreeItemType.DIRECTORY) { | ||
dirs.append ((GMenu.TreeDirectory) item); | ||
} | ||
} | ||
|
||
return dirs; | ||
} | ||
|
||
public List<GMenu.TreeEntry> get_entries_flat (GMenu.TreeDirectory directory) { | ||
var entries = new List<GMenu.TreeEntry> (); | ||
|
||
foreach (GMenu.TreeItem item in directory.get_contents ()) { | ||
switch (item.get_type ()) { | ||
case GMenu.TreeItemType.DIRECTORY: | ||
entries.concat (get_entries_flat ((GMenu.TreeDirectory) item)); | ||
break; | ||
case GMenu.TreeItemType.ENTRY: | ||
entries.append ((GMenu.TreeEntry) item); | ||
break; | ||
} | ||
} | ||
return entries; | ||
} | ||
|
||
public DesktopAppInfo get_desktop_app_info (GMenu.TreeEntry entry) { | ||
return new DesktopAppInfo.from_filename (entry.get_desktop_file_path ()); | ||
} | ||
|
||
/* Launch an application described in DesktopAppInfo */ | ||
public void launch_desktop_app_info (DesktopAppInfo info) { | ||
try { | ||
info.launch (null, new AppLaunchContext ()); | ||
} catch (Error error) { | ||
stdout.printf ("Error: %s\n", error.message); | ||
} | ||
} | ||
} |
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,45 @@ | ||
using Cairo; | ||
using Gtk; | ||
|
||
public class PanelClockWindow : Window { | ||
public PanelClockWindow () { | ||
set_type_hint (Gdk.WindowTypeHint.DOCK); | ||
set_decorated (false); | ||
resizable = false; | ||
var calendar = new Calendar (); | ||
add (calendar); | ||
} | ||
} | ||
|
||
public class PanelClock : MenuItem { | ||
private string clock_label = "00:00"; | ||
private PanelClockWindow window; | ||
|
||
public PanelClock() { | ||
window = new PanelClockWindow (); | ||
deselect.connect (() => { | ||
window.hide (); | ||
}); | ||
|
||
select.connect (() => { | ||
var screen = get_screen(); | ||
Gdk.Rectangle rect; | ||
screen.get_monitor_geometry (screen.get_primary_monitor(), out rect); | ||
|
||
window.show_all (); | ||
var x = rect.x + rect.width - get_allocated_width (); | ||
if (x + window.get_allocated_width () > rect.x + rect.width) | ||
x = rect.x + rect.width - window.get_allocated_width (); | ||
|
||
window.move (x, get_allocated_height ()); | ||
|
||
}); | ||
update_data(); | ||
} | ||
|
||
public void update_data () | ||
{ | ||
// Update the label here | ||
set_label (clock_label); | ||
} | ||
} |
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,41 @@ | ||
using Gtk; | ||
using Gdk; | ||
using Cairo; | ||
|
||
public class PanelHorizontal : Gtk.Window { | ||
private Alignment box; | ||
private Gdk.Rectangle rect; | ||
private MenuBar bar; | ||
|
||
public PanelHorizontal () { | ||
set_type_hint (Gdk.WindowTypeHint.DOCK); | ||
box = new Alignment (1, 0, 0, 0); | ||
add (box); | ||
set_decorated (false); | ||
resizable = false; | ||
|
||
bar = new MenuBar (); | ||
|
||
box.add (bar); | ||
|
||
var clock = new PanelClock(); | ||
bar.append (clock); | ||
|
||
box.show_all(); | ||
|
||
var screen = get_screen(); | ||
screen.get_monitor_geometry (screen.get_primary_monitor(), out rect); | ||
move (rect.x, rect.y); | ||
} | ||
|
||
public override void get_preferred_width (out int min, out int max) { | ||
// TODO | ||
min = max = rect.width; | ||
} | ||
|
||
public override void get_preferred_height (out int min, out int max) { | ||
// TODO | ||
min = max = 32; | ||
} | ||
|
||
} |
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,19 @@ | ||
using Gtk; | ||
|
||
public class PanelItem : MenuItem { | ||
|
||
private string icon_name; | ||
private int type; | ||
|
||
public PanelItem () { | ||
set_label("ddd"); | ||
} | ||
|
||
public void update_data (string icon_name, string label, int type) | ||
{ | ||
this.icon_name = icon_name; | ||
this.type = type; | ||
|
||
set_label(label); | ||
} | ||
} |
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,51 @@ | ||
using Gtk; | ||
|
||
public class PanelMenuBox : Window { | ||
public PanelMenuBox () { | ||
add_events (Gdk.EventMask.BUTTON_PRESS_MASK | ||
| Gdk.EventMask.BUTTON_RELEASE_MASK | ||
| Gdk.EventMask.POINTER_MOTION_MASK); | ||
|
||
set_size_request (100, 100); | ||
set_type_hint (Gdk.WindowTypeHint.MENU); | ||
set_decorated (false); | ||
set_resizable (false); | ||
set_focus_on_map (true); | ||
set_accept_focus (true); | ||
|
||
} | ||
|
||
public override bool map_event (Gdk.Event event) { | ||
var device = get_current_event_device(); | ||
|
||
if (device == null) { | ||
var display = get_display (); | ||
var manager = display.get_device_manager (); | ||
var devices = manager.list_devices (Gdk.DeviceType.MASTER).copy(); | ||
device = devices.data; | ||
} | ||
var keyboard = device; | ||
var pointer = device; | ||
|
||
if (device.get_source() == Gdk.InputSource.KEYBOARD) { | ||
pointer = device.get_associated_device (); | ||
} else { | ||
keyboard = device.get_associated_device (); | ||
} | ||
|
||
|
||
var status = keyboard.grab(get_window(), Gdk.GrabOwnership.WINDOW, true, Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK, null, Gdk.CURRENT_TIME); | ||
status = pointer.grab(get_window(), Gdk.GrabOwnership.WINDOW, true, Gdk.EventMask.BUTTON_PRESS_MASK, null, Gdk.CURRENT_TIME); | ||
return true; | ||
} | ||
|
||
public override bool button_press_event (Gdk.EventButton event) { | ||
var device = get_current_event_device(); | ||
var secondary = device.get_associated_device(); | ||
device.ungrab(Gdk.CURRENT_TIME); | ||
secondary.ungrab(Gdk.CURRENT_TIME); | ||
hide(); | ||
return false; | ||
} | ||
|
||
} |
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,6 @@ | ||
using Gtk; | ||
using Cairo; | ||
|
||
public class PanelMenu : Menu { | ||
|
||
} |