Skip to content

Instantly share code, notes, and snippets.

@voldyman
Created December 27, 2012 15:32
Show Gist options
  • Save voldyman/4389076 to your computer and use it in GitHub Desktop.
Save voldyman/4389076 to your computer and use it in GitHub Desktop.
Simple code to change the wallpaper
/* compile using: valac --pkg gtk+-3.0 wall.vala */
using Gtk;
using Gdk;
using Cairo;
public class AppWin : Gtk.Window {
construct {
app_paintable = true;
decorated = false;
resizable = false;
set_keep_above (true);
skip_taskbar_hint = true; // no taskbar
skip_pager_hint = true;
//type = Gtk.WindowType.POPUP;
set_type_hint (WindowTypeHint.DESKTOP);
set_visual (get_screen ().get_rgba_visual());
}
static const Gtk.ActionEntry[] main_entries = {
{ "Quit", Gtk.Stock.QUIT, N_("Quit"), "<Control>q", N_("Quit"), action },
{ "Test", "Test", N_("Want to change the wallpaper"), "<Control><Shift>c", N_("Copy the selected text"),
action },
{ "About", "About", N_("elementary team ?"), null, N_("Show about window"), action }
};
void action () {
print ("Action Detected\n");
}
public AppWin () {
var evBox = new Gtk.EventBox ();
this.add (evBox);
evBox.draw.connect(on_draw_cb);
destroy.connect (Gtk.main_quit);
Gtk.UIManager ui = new Gtk.UIManager ();
Gtk.ActionGroup main_actions;
const string ui_string = """
<ui>
<popup name="AppMenu">
<menuitem name="Test" action="Test"/>
<separator />
<menuitem name="About" action="About"/>
</popup>
</ui>
""";
main_actions = new Gtk.ActionGroup ("MainActionGroup");
main_actions.set_translation_domain ("pantheon-terminal");
main_actions.add_actions (main_entries, this);
try {
ui.add_ui_from_string (ui_string, -1);
} catch (Error e) {
error ("Couldn't load the UI: %s", e.message);
}
var menu = ui.get_widget ("ui/AppMenu") as Gtk.Menu;
menu.show_all ();
ui.insert_action_group (main_actions, 0);
ui.ensure_update ();
evBox.button_press_event.connect ((event) => {
print ("Button Pressed");
switch (event.button) {
case Gdk.BUTTON_PRIMARY:
return false;
case Gdk.BUTTON_SECONDARY :
menu.select_first (false);
menu.popup (null, null, null, event.button, event.time);
return true;
}
return false;
});
show_all ();
}
bool on_draw_cb (Context cr) {
Gdk.Rectangle screen = Gdk.Rectangle () { x = 0, y = 0, width = get_screen ().width(), height = get_screen ().height() };
this.set_size_request (screen.width, screen.height);
var pixbuf = new Pixbuf.from_file_at_scale ("/home/voldyman/Pictures/wallpaper-1260152.jpg", screen.width,screen.height, true);
cairo_set_source_pixbuf (cr, pixbuf, 0,0);
cr.paint ();
return true;
}
/*
protected override bool draw (Context cr) {
base.draw (cr);
Gdk.Rectangle screen = Gdk.Rectangle () { x = 0, y = 0, width = get_screen ().width(), height = get_screen ().height() };
this.set_size_request (screen.width, screen.height);
var pixbuf = new Pixbuf.from_file_at_scale ("/home/voldyman/Pictures/wallpaper-1260152.jpg", screen.width,screen.height, true);
cairo_set_source_pixbuf (cr, pixbuf, 0,0);
cr.paint ();
return false;
}*/
}
int main (string[] args) {
Gtk.init (ref args);
var win = new AppWin ();
win.destroy.connect (Gtk.main_quit);
win.show_all ();
Gtk.main ();
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment