Skip to content

Instantly share code, notes, and snippets.

@milisarge
Created September 8, 2017 14:24
Show Gist options
  • Select an option

  • Save milisarge/386d2fb152518c3fc32bbf47d04aa954 to your computer and use it in GitHub Desktop.

Select an option

Save milisarge/386d2fb152518c3fc32bbf47d04aa954 to your computer and use it in GitHub Desktop.
Systray example in vala
using Gtk;
public class Main {
class AppStatusIcon : Window {
private StatusIcon trayicon;
private Gtk.Menu menuSystem;
private AboutDialog aboutDialog;
public AppStatusIcon() {
/* Create tray icon */
trayicon = new StatusIcon.from_icon_name("gtk-home");
trayicon.set_tooltip_text ("Milis Linux Bildirim Sistemi");
trayicon.set_visible(true);
trayicon.activate.connect(about_clicked);
create_menuSystem();
trayicon.popup_menu.connect(menuSystem_popup);
}
/* Create menu for right button */
public void create_menuSystem() {
menuSystem = new Gtk.Menu();
menuSystem2 = new Gtk.Menu();
var box = new Box (Orientation.HORIZONTAL, 6);
var icon = new Gtk.Image.from_icon_name ("gtk-about", IconSize.MENU);
var label = new Label ("Hakkında");
var menuItem = new Gtk.MenuItem();
box.add (icon);
box.add (label);
menuItem.add (box);
menuItem.activate.connect(about_clicked);
menuSystem.append(menuItem);
var box3 = new Box (Orientation.HORIZONTAL, 6);
var icon3 = new Gtk.Image.from_icon_name ("gtk-quit", IconSize.MENU);
var label3 = new Label ("Çıkış");
var menuItem3 = new Gtk.MenuItem();
box3.add (icon3);
box3.add (label3);
menuItem3.add (box3);
menuItem3.activate.connect(Gtk.main_quit);
menuSystem.append(menuItem3);
var box2 = new Box (Orientation.HORIZONTAL, 6);
var icon2 = new Gtk.Image.from_icon_name ("gtk-about", IconSize.MENU);
var label2 = new Label ("MPS");
var menuItem2 = new Gtk.MenuItem();
box2.add (icon2);
box2.add (label2);
menuItem2.add (box2);
menuItem2.activate.connect(about_clicked);
menuSystem.append(menuItem2);
menuSystem.show_all();
}
private void menuSystem_popup(uint button, uint time) {
menuSystem.popup(null, null, null, button, time);
}
private void about_clicked() {
if (aboutDialog == null) {
aboutDialog = new AboutDialog();
aboutDialog.set_version("1.0");
aboutDialog.set_program_name("Milis Linux Bildirim Sistemi");
aboutDialog.set_comments("Milis Linux bildirimlerini kolayca takip etmenizi sağlar.");
aboutDialog.set_copyright("Milis Linux");
}
aboutDialog.run();
aboutDialog.hide();
}
}
public static int main (string[] args) {
Gtk.init(ref args);
var App = new AppStatusIcon();
//App.hide();
Gtk.main();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment