module modules.monitors; import std.conv; import std.string; extern (C) { enum Relation { left_of, right_of, above, below, same_as, } struct x_change { immutable(char)* first_monitor; immutable(char)* second_monitor; int is_position; Relation position; int primary; } struct x_monitor { char[10] name = "\0"; int width; int height; int primary; } struct x_info { int count; x_monitor[5] monitor; } int XInfo(x_info* info); int XChange(x_change* settings); } struct Monitor { string name; bool primary; int width; int height; } Monitor[] getMonitorsInfo() { Monitor[] m; x_info monitors; if (!XInfo(&monitors)) { foreach (i; 0 .. monitors.count) { Monitor current; current.name = fromStringz(monitors.monitor[i].name.idup); current.primary = to!bool(monitors.monitor[i].primary); current.width = monitors.monitor[i].width; current.height = monitors.monitor[i].height; m ~= current; } } return m; } bool setPrimaryMonitor(string monitor) { x_change settings; settings.first_monitor = toStringz(monitor); settings.primary = 1; settings.is_position = 0; return to!bool(XChange(&settings)); } bool swapMonitors(string first, string second, Relation position) { x_change settings; settings.first_monitor = toStringz(first); settings.second_monitor = toStringz(second); settings.is_position = 1; settings.position = position; settings.primary = 0; return to!bool(XChange(&settings)); }