From 3af89b858c7d86cb23bb75a68a3643449a4b15c3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 10 Mar 2014 20:17:35 +0100 Subject: add EDID support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blueshift_idcrtc.c | 15 ++++++++++----- src/monitor.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/blueshift_idcrtc.c b/src/blueshift_idcrtc.c index d55f6eb..c4ddf3b 100644 --- a/src/blueshift_idcrtc.c +++ b/src/blueshift_idcrtc.c @@ -65,6 +65,7 @@ int main(int argc, char** argv) int screen_count; xcb_screen_t* screens; int screen_i; + int i; (void) argc; (void) argv; @@ -238,7 +239,7 @@ int main(int argc, char** argv) char* atom_data; atom_cookie = xcb_randr_get_output_property(connection, outputs[output_i], *atoms, - XCB_GET_PROPERTY_TYPE_ANY, 0, 0, 0, 0); + XCB_GET_PROPERTY_TYPE_ANY, 0, 128, 0, 0); atom_reply = xcb_randr_get_output_property_reply(connection, atom_cookie, &error); @@ -256,11 +257,15 @@ int main(int argc, char** argv) atom_data_ = xcb_randr_get_output_property_data(atom_reply); length = xcb_randr_get_output_property_data_length(atom_reply); - atom_data = alloca((length + 1) * sizeof(char)); - memcpy(atom_data, atom_data_, length * sizeof(char)); - *(atom_data + length) = 0; + atom_data = alloca((2 * length + 1) * sizeof(char)); + for (i = 0; i < length; i++) + { + *(atom_data + i * 2 + 0) = "0123456789abcdef"[(*(atom_data_ + i) >> 4) & 15]; + *(atom_data + i * 2 + 1) = "0123456789abcdef"[(*(atom_data_ + i) >> 0) & 15]; + } + *(atom_data + 2 * length) = 0; - /* printf(" %s: %s\n", atom_name, atom_data); TODO */ + printf(" %s: %s\n", atom_name, atom_data); free(atom_reply); } diff --git a/src/monitor.py b/src/monitor.py index 70a86e6..7e81d5a 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -267,6 +267,18 @@ class Screens: rc += screen.find_by_connected(status) return rc + def find_by_edid(self, edid): + ''' + Find output by extended display identification data + + @param edid:str? The extended display identification data of the monitor + @return :list Matching outputs + ''' + rc = [] + for screen in self.screens: + rc += screen.find_by_edid(edid) + return rc + def __contains__(self, other): return other in self.screens def __getitem__(self, index): @@ -350,6 +362,19 @@ class Screen: rc.append(self.outputs[i]) return rc + def find_by_edid(self, edid): + ''' + Find output by extended display identification data + + @param edid:str? The extended display identification data of the monitor + @return :list Matching outputs + ''' + rc = [] + for i in range(len(self.outputs)): + if self.outputs[i].edid == edid: + rc.append(self.outputs[i]) + return rc + def __repr__(self): ''' Return a string representation of the instance @@ -366,6 +391,7 @@ class Output: @variable heigthmm:int? The physical height of the monitor, measured in millimetres, `None` if unknown or not connected @variable crtc:int? The CRTC index, `None` if not connected @variable screen:int? The screen index, `None` if none + @variable edid:str? Extended display identification data, `None` if none ''' def __init__(self): ''' @@ -377,14 +403,15 @@ class Output: self.heightmm = None self.crtc = None self.screen = None + self.edid = None def __repr__(self): ''' Return a string representation of the instance ''' - rc = [self.name, self.connected, self.widthmm, self.heightmm, self.crtc, self.screen] - rc = tuple([self.name] + list(map(lambda x : repr(x), rc[1:]))) - rc = '[Name: %s, Connected: %s, Width: %s, Height: %s, CRTC: %s, Screen: %s]' % rc + rc = [self.name, self.connected, self.widthmm, self.heightmm, self.crtc, self.screen, self.edid] + rc = tuple(rc[:1] + list(map(lambda x : repr(x), rc[1 : -1])) + [str(rc[-1])]) + rc = '[Name: %s, Connected: %s, Width: %s, Height: %s, CRTC: %s, Screen: %s, EDID: %s]' % rc return rc def list_screens(): @@ -423,6 +450,8 @@ def list_screens(): output.widthmm, output.heightmm = None, None elif line.startswith('CRTC: '): output.crtc = int(line[len('CRTC: '):]) + elif line.startswith('EDID: '): + output.edid = line[len('EDID: '):] rc = Screens() rc.screens = screens return rc -- cgit v1.2.3-70-g09d2