stevee

My wayland statusbar
git clone git://gtms.dev/stevee
Log | Files | Refs | README | LICENSE

Monitor.zig (1134B)


      1 const wl = @import("wayland").client.wl;
      2 
      3 const Bar = @import("Bar.zig");
      4 const Tags = @import("Tags.zig");
      5 const Monitor = @This();
      6 
      7 const state = &@import("root").state;
      8 
      9 output: *wl.Output,
     10 globalName: u32,
     11 scale: i32,
     12 
     13 bar: ?*Bar,
     14 tags: *Tags,
     15 
     16 pub fn create(registry: *wl.Registry, name: u32) !*Monitor {
     17     const self = try state.gpa.create(Monitor);
     18     self.output = try registry.bind(name, wl.Output, 4);
     19     self.globalName = name;
     20     self.scale = 1;
     21 
     22     self.bar = null;
     23     self.tags = try Tags.create(self);
     24 
     25     self.output.setListener(*Monitor, listener, self);
     26     return self;
     27 }
     28 
     29 pub fn destroy(self: *Monitor) void {
     30     if (self.bar) |bar| {
     31         bar.destroy();
     32     }
     33     self.tags.destroy();
     34     state.gpa.destroy(self);
     35 }
     36 
     37 fn listener(_: *wl.Output, event: wl.Output.Event, monitor: *Monitor) void {
     38     switch (event) {
     39         .scale => |scale| {
     40             monitor.scale = scale.factor;
     41         },
     42         .geometry => {},
     43         .mode => {},
     44         .done => {
     45             if (monitor.bar) |_| {} else {
     46                 monitor.bar = Bar.create(monitor) catch return;
     47             }
     48         },
     49     }
     50 }