Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: src/platform/autox/autox.py

Issue 1386002: autox: Fix race condition and add get_screen_size(). (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import re 7 import re
8 import select 8 import select
9 import time 9 import time
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 ax.send_hotkey("Ctrl+L") 35 ax.send_hotkey("Ctrl+L")
36 ax.send_text("http://www.example.org/\n") 36 ax.send_text("http://www.example.org/\n")
37 37
38 # Create a window and wait for it to get the focus. 38 # Create a window and wait for it to get the focus.
39 win = ax.create_and_map_window(width=200, height=200, title='test') 39 win = ax.create_and_map_window(width=200, height=200, title='test')
40 info = ax.get_window_info(win.id) 40 info = ax.get_window_info(win.id)
41 ax.await_condition( 41 ax.await_condition(
42 lambda: info.is_focused, 42 lambda: info.is_focused,
43 desc='Waiting for window 0x%x to be focused' % win.id) 43 desc='Waiting for window 0x%x to be focused' % win.id)
44 ax.destroy_window(win) 44 win.destroy()
45 45
46 # Create an override-redirect window and check that it appears in 46 # Create an override-redirect window and check that it appears in
47 # the position that it requested. 47 # the position that it requested.
48 popup_win = ax.create_and_map_window( 48 popup_win = ax.create_and_map_window(
49 x=200, y=200, width=200, height=200, 49 x=200, y=200, width=200, height=200,
50 title='popup', override_redirect=True) 50 title='popup', override_redirect=True)
51 popup_info = ax.get_window_info(popup_win.id) 51 popup_info = ax.get_window_info(popup_win.id)
52 ax.await_condition( 52 ax.await_condition(
53 lambda: popup_info.get_geometry() == (200, 200, 200, 200), 53 lambda: popup_info.get_geometry() == (200, 200, 200, 200),
54 desc='Checking window 0x%x\'s geometry' % popup_win.id) 54 desc='Checking window 0x%x\'s geometry' % popup_win.id)
55 ax.destroy_window(popup_win) 55 popup_win.destroy()
56 """ 56 """
57 57
58 # Map of characters that can be passed to send_text() that differ 58 # Map of characters that can be passed to send_text() that differ
59 # from their X keysym names. 59 # from their X keysym names.
60 __chars_to_keysyms = { 60 __chars_to_keysyms = {
61 ' ': 'space', 61 ' ': 'space',
62 '\n': 'Return', 62 '\n': 'Return',
63 '\t': 'Tab', 63 '\t': 'Tab',
64 '~': 'asciitilde', 64 '~': 'asciitilde',
65 '!': 'exclam', 65 '!': 'exclam',
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 """ 315 """
316 self.__display.sync() 316 self.__display.sync()
317 while self.__display.pending_events(): 317 while self.__display.pending_events():
318 event = self.__display.next_event() 318 event = self.__display.next_event()
319 if event.type == X.ConfigureNotify: 319 if event.type == X.ConfigureNotify:
320 info = self.__windows[event.window.id] 320 info = self.__windows[event.window.id]
321 info.x = event.x 321 info.x = event.x
322 info.y = event.y 322 info.y = event.y
323 info.width = event.width 323 info.width = event.width
324 info.height = event.height 324 info.height = event.height
325 elif event.type == X.DestroyNotify:
326 del self.__windows[event.window.id]
325 elif event.type == X.Expose: 327 elif event.type == X.Expose:
326 info = self.__windows[event.window.id] 328 info = self.__windows[event.window.id]
327 info.was_exposed = True 329 info.was_exposed = True
328 if info.expose_callback: 330 if info.expose_callback:
329 info.expose_callback(event) 331 info.expose_callback(event)
330 else: 332 else:
331 event.window.clear_area( 333 event.window.clear_area(
332 event.x, event.y, event.width, event.height) 334 event.x, event.y, event.width, event.height)
333 elif event.type == X.FocusIn or event.type == X.FocusOut: 335 elif event.type == X.FocusIn or event.type == X.FocusOut:
334 self.__windows[event.window.id].is_focused = \ 336 self.__windows[event.window.id].is_focused = \
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 Args: 508 Args:
507 x, y: int position of window 509 x, y: int position of window
508 width, height: int dimensions of window 510 width, height: int dimensions of window
509 title: str containing the window's title 511 title: str containing the window's title
510 override_redirect: whether this is an override-redirect 512 override_redirect: whether this is an override-redirect
511 ("popup", in GTK's parlance) window. override-redirect 513 ("popup", in GTK's parlance) window. override-redirect
512 windows are mapped, placed, and sized without any window 514 windows are mapped, placed, and sized without any window
513 manager involvement. 515 manager involvement.
514 516
515 Returns: 517 Returns:
516 python-xlib Window object (but see destroy_window()) 518 python-xlib Window object
517 """ 519 """
520 # Sync before creating the window. It's possible that we're
521 # reusing the ID from an already-destroyed window that we haven't
522 # seen a DestroyNotify event about yet, and we want to make sure
523 # that its WindowInfo object gets cleaned up before we register ours.
524 self.sync()
525
518 win = self.__root.create_window( 526 win = self.__root.create_window(
519 x, y, width, height, border_width=0, 527 x, y, width, height, border_width=0,
520 depth=X.CopyFromParent, 528 depth=X.CopyFromParent,
521 override_redirect=override_redirect, 529 override_redirect=override_redirect,
522 background_pixel=self.__display.screen().white_pixel, 530 background_pixel=self.__display.screen().white_pixel,
523 event_mask = (X.ExposureMask | 531 event_mask = (X.ExposureMask |
524 X.FocusChangeMask | 532 X.FocusChangeMask |
525 X.StructureNotifyMask)) 533 X.StructureNotifyMask))
526 534 info = self.WindowInfo(
527 info = AutoX.WindowInfo(
528 x, y, width, height, expose_callback=expose_callback) 535 x, y, width, height, expose_callback=expose_callback)
529 self.__windows[win.id] = info 536 self.__windows[win.id] = info
530 537
531 if title: 538 if title:
532 win.set_wm_name(title) 539 win.set_wm_name(title)
533 utf8_atom = self.__display.get_atom('UTF8_STRING') 540 utf8_atom = self.__display.get_atom('UTF8_STRING')
534 win.change_property( 541 win.change_property(
535 self.__display.get_atom('_NET_WM_NAME'), 542 self.__display.get_atom('_NET_WM_NAME'),
536 utf8_atom, 8, data=title) 543 utf8_atom, 8, data=title)
537 544
538 win.map() 545 win.map()
539 self.await_condition( 546 self.await_condition(
540 lambda: info.was_exposed, 547 lambda: info.was_exposed,
541 desc='Waiting for window 0x%x to be exposed' % win.id) 548 desc='Waiting for window 0x%x to be exposed' % win.id)
549
542 return win 550 return win
543 551
544 def destroy_window(self, window):
545 """Destroy a window returned by create_and_map_window().
546
547 In addition to calling the window's destroy() method, this method
548 cleans up internal state that was being used to track the window.
549
550 Args:
551 window: python-xlib Window object
552 """
553 del self.__windows[window.id]
554 window.destroy()
555
556 def get_window_info(self, window_id): 552 def get_window_info(self, window_id):
557 """Get an object containing information about a window. 553 """Get an object containing information about a window.
558 554
559 Args: 555 Args:
560 window_id: int ID of the window 556 window_id: int ID of the window
561 557
562 Returns: 558 Returns:
563 WindowInfo object (should be treated as read-only) 559 WindowInfo object (should be treated as read-only)
564 """ 560 """
565 return self.__windows[window_id] 561 return self.__windows[window_id]
(...skipping 25 matching lines...) Expand all
591 """Get the root window's _NET_ACTIVE_WINDOW property. 587 """Get the root window's _NET_ACTIVE_WINDOW property.
592 588
593 Returns: 589 Returns:
594 int window ID from the property, or None if unset 590 int window ID from the property, or None if unset
595 """ 591 """
596 reply = self.__root.get_property( 592 reply = self.__root.get_property(
597 self.__display.get_atom('_NET_ACTIVE_WINDOW'), Xatom.WINDOW, 0, 1) 593 self.__display.get_atom('_NET_ACTIVE_WINDOW'), Xatom.WINDOW, 0, 1)
598 if not reply: 594 if not reply:
599 return None 595 return None
600 return reply.value[0] 596 return reply.value[0]
597
598 def get_screen_size(self):
599 """Get the current dimensions of the root window.
600
601 Returns:
602 tuple with two ints: (width, height)
603 """
604 reply = self.__root.get_geometry()
605 return (reply.width, reply.height)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698