Advertisement
Guest User

Untitled

a guest
Apr 16th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.00 KB | None | 0 0
  1.  
  2. public const int [] higher_pid = {}; //lower nice value
  3. public const int [] lower_pid  = {}; //higher nice value
  4.  
  5.  
  6. public enum Priority {
  7.     LOW = 15,
  8.     NORMAL = 0,
  9.     HIGH = -15
  10. }
  11.  
  12. public static void main (string [] args) {
  13.     Gdk.init (ref args);
  14.    
  15.     for (var i=0;i<higher_pid.length;i++)
  16.         set_priority (higher_pid, Priority.HIGH);
  17.     for (var i=0;i<lower_pid.length;i++)
  18.         set_priority (higher_pid, Priority.LOW);
  19.    
  20.     var screen = Wnck.Screen.get_default ();
  21.     screen.active_window_changed.connect ( (prev) => {
  22.         if (prev != null)
  23.             set_priority (prev.get_pid (), Priority.NORMAL);
  24.         set_priority (screen.get_active_window ().get_pid (), Priority.HIGH);
  25.     });
  26.    
  27.     var m = new MainLoop ();
  28.     m.run ();
  29. }
  30.  
  31. public static void set_priority (int pid, Priority p) {
  32.     try {
  33.         Process.spawn_command_line_sync ("renice "+((int)p).to_string ()+" -p "+pid.to_string ());
  34.     } catch (Error e) { warning (e.message); }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement