Esempio n. 1
0
 def _xrandr_switch_mod(self, mmid, virtualres):
     '''_xrandr_switch that uses the xrandr python module'''
     import xrandr
     screen = xrandr.get_current_screen()
     sizeidx = -1
     for i,s in enumerate(screen.get_available_sizes()):
         if s.width != virtualres[0] or s.height != virtualres[1]: continue
         if mmid in screen.get_available_rates_for_size_index(i):
             res = '%dx%d' % ( s.width, s.height )
             sizeidx = i
             break
     if sizeidx < 0:
         raise Exception( 'could not switch to metamode %d: resolution not found' % mmid )
     screen.set_size_index(sizeidx)
     screen.set_refresh_rate(mmid)
     logging.info('switching to metamode %d: [%d] %s / %s'%(mmid,sizeidx,res,mmid))
     screen.apply_config()
Esempio n. 2
0
 def _xrandr_switch_mod(self, mmid, virtualres):
     '''_xrandr_switch that uses the xrandr python module'''
     import xrandr
     screen = xrandr.get_current_screen()
     sizeidx = -1
     for i, s in enumerate(screen.get_available_sizes()):
         if s.width != virtualres[0] or s.height != virtualres[1]: continue
         if mmid in screen.get_available_rates_for_size_index(i):
             res = '%dx%d' % (s.width, s.height)
             sizeidx = i
             break
     if sizeidx < 0:
         raise Exception(
             'could not switch to metamode %d: resolution not found' % mmid)
     screen.set_size_index(sizeidx)
     screen.set_refresh_rate(mmid)
     logging.info('switching to metamode %d: [%d] %s / %s' %
                  (mmid, sizeidx, res, mmid))
     screen.apply_config()
Esempio n. 3
0
 def __init__(self):
     self.log = logging.getLogger('xrandr')
     self.screen = xrandr.get_current_screen()
     if not xrandr.has_extension():
         raise Exception('No XRandR extension found')
Esempio n. 4
0
class Rotate:
    screen=xrandr.get_current_screen();

    def getRotation(self):
        return self.screen.get_current_rotation();

    def setRotation(self,rotation):
        # There is not point in resetting and existing rotation
        if(rotation!=self.screen.get_current_rotation()): 
            self.screen.set_rotation(rotation);
            self.screen.apply_config();
            self.rotateWacom(rotation);
            self.rotateButtons(rotation);

    def setNextRotation(self):
        current_rotation=self.getRotation();

        # The codes go up as powers of two: 1,2,4,8
        #so we log2 it and increment by 1.
        next_rotation=int((math.log(current_rotation)/math.log(2)+1)%4);
        
        self.setRotation(2**next_rotation);

    def listDevices(self):
        process=subprocess.Popen(["xsetwacom","--list"],stdout=subprocess.PIPE)
        process.wait()

        devices=[]
        for line in process.stdout:
            line=line.strip();
            # Line has format "device-name-with-spaces many-spaces INFO"
            # We do not want the INFO part..
            parts=line.split('  '); # Split at many (more than one) spaces
            dev_name=parts[0].strip();
            devices.append(dev_name)

        return devices

        # Correct the rotation of the stylus input
    def rotateWacom(self,rotation):
	codes={xrandr.RR_ROTATE_0:"none",
	       xrandr.RR_ROTATE_90:"ccw",
	       xrandr.RR_ROTATE_180:"half",
	       xrandr.RR_ROTATE_270:"cw"};
	for i in self.listDevices():
            os.system("xsetwacom set \""+i+"\" Rotate "+codes[rotation]);

    # Correct the rotation of the arrow buttons.
    def rotateButtons(self,rotation):
        keysim=["71","6d","6f","6e"];
        keycodes={xrandr.RR_ROTATE_0:[105,108,106,103],
                  xrandr.RR_ROTATE_90:[103,105,108,106],
                  xrandr.RR_ROTATE_180:[106,103,105,108],
                  xrandr.RR_ROTATE_270:[108,106,103,105]};

        keycode_command="";
	for i in keysim:
            toCode=keycodes[rotation].pop();
            keycode_command+=" "+str(i)+" "+str(toCode);
            
        if(os.getuid()==0):
            os.system("setkeycodes "+keycode_command);
        else:
            os.system("gksudo -D\"Auto-Rotate Daemon\" setkeycodes "+keycode_command);
Esempio n. 5
0
def main():
    parser = OptionParser(version=__version__)
    parser.add_option(
        "-v",
        "",
        action="store_true",
        dest="version",
        default=False,
        #TRANSLATORS: command line option
        help=_("show current xrandr version"))
    parser.add_option(
        "--verbose",
        "",
        action="store_true",
        dest="verbose",
        default=False,
        #TRANSLATORS: command line option
        help=_("show additional information"))
    parser.add_option(
        "-s",
        "--size",
        default=None,
        action="store",
        type="int",
        dest="size",
        #TRANSLATORS: command line option
        help=_("set the screen reolsution to the given size id"))
    parser.add_option(
        "-r",
        "--rate",
        default=None,
        action="store",
        type="int",
        dest="rate",
        #TRANSLATORS: command line option
        help=_("set the given refresh rate"))
    parser.add_option(
        "-o",
        "--rotate",
        default=None,
        action="store",
        type="string",
        dest="rotate",
        #TRANSLATORS: command line option
        help=_("rotate the screen. supported values are "
               "normal, left, inverted, right or 0, 90, 180, "
               "270"))
    parser.add_option(
        "--output",
        "",
        default=None,
        action="store",
        type="string",
        dest="output",
        #TRANSLATORS: command line option
        help=_("select an available output"))
    parser.add_option(
        "--preferred",
        "",
        action="store_true",
        dest="output_preferred",
        #TRANSLATORS: command line option
        help=_("choose the preferred resolution and rate"))
    parser.add_option(
        "--mode",
        "",
        action="store",
        type="int",
        dest="output_mode",
        #TRANSLATORS: command line option
        help=_("set to the mode of the given index number"))
    parser.add_option(
        "--off",
        "",
        action="store_true",
        dest="output_disable",
        #TRANSLATORS: command line option
        help=_("turn off the selected output"))
    parser.add_option(
        "--left-of",
        "",
        default=None,
        action="store",
        type="string",
        dest="output_left",
        #TRANSLATORS: command line option
        help=_("move the output left of the given one"))
    parser.add_option(
        "--right-of",
        "",
        default=None,
        action="store",
        type="string",
        dest="output_right",
        #TRANSLATORS: command line option
        help=_("move the output right of the given one"))
    parser.add_option(
        "--above",
        "",
        default=None,
        action="store",
        type="string",
        dest="output_above",
        #TRANSLATORS: command line option
        help=_("move the output above of the given one"))
    parser.add_option(
        "--below",
        "",
        default=None,
        action="store",
        type="string",
        dest="output_below",
        #TRANSLATORS: command line option
        help=_("move the output below of the given one"))
    parser.add_option(
        "--same-as",
        "",
        default=None,
        action="store",
        type="string",
        dest="output_same",
        #TRANSLATORS: command line option
        help=_("move the output to the position of the "
               "given one"))
    (options, args) = parser.parse_args()

    if xrandr.has_extension():
        if options.version:
            print "%x.%s" % xrandr.XRANDR_VERSION
            sys.exit()
        else:
            print _("XRandR %s.%s") % xrandr.XRANDR_VERSION
    else:
        print _("The XRandR extension is not available")
        sys.exit(1)

    changed_1_0 = False

    screen = xrandr.get_current_screen()

    if options.size != None:
        screen.set_size_index(options.size)
        changed_1_0 = True
    if options.rate:
        screen.set_refresh_rate(options.rate)
        changed_1_0 = True
    if options.rotate:
        if options.rotate in [_("normal"), "0"]:
            rotation = xrandr.RR_ROTATE_0
        elif options.rotate in [_("right"), "90"]:
            rotation = xrandr.RR_ROTATE_90
        elif options.rotate in [_("inverted"), "180"]:
            rotation = xrandr.RR_ROTATE_180
        elif options.rotate in [_("left"), "270"]:
            rotation = xrandr.RR_ROTATE_270
        else:
            print _("Invalid orientation")
            sys.exit(1)
        screen.set_rotation(rotation)
        changed_1_0 = True
    if changed_1_0:
        screen.apply_config()
    elif options.output:
        output = screen.get_output_by_name(options.output)
        if not output:
            print _("Output does not exist")
            sys.exit(1)
        if options.output_disable:
            output.disable()
        elif options.output_preferred:
            output.set_to_preferred_mode()
        elif options.output_mode != None:
            output.set_to_mode(options.output_mode)
        if options.output_left:
            output.set_relation(options.output_left, xrandr.RELATION_LEFT_OF)
        elif options.output_right:
            output.set_relation(options.output_right, xrandr.RELATION_RIGHT_OF)
        elif options.output_above:
            output.set_relation(options.output_above, xrandr.RELATION_ABOVE)
        elif options.output_below:
            output.set_relation(options.output_below, xrandr.RELATION_BELOW)
        elif options.output_same:
            output.set_relation(options.output_same, xrandr.RELATION_SAME_AS)
        screen.apply_output_config()
    else:
        screen.print_info(options.verbose)
Esempio n. 6
0
def main():
    parser = OptionParser(version=__version__)
    parser.add_option("-v", "",
                      action="store_true", dest="version",
                      default=False,
                      #TRANSLATORS: command line option
                      help=_("show current xrandr version"))
    parser.add_option("--verbose", "",
                      action="store_true", dest="verbose",
                      default=False,
                      #TRANSLATORS: command line option
                      help=_("show additional information"))
    parser.add_option("-s", "--size",
                      default=None,
                      action="store", type="int", dest="size",
                      #TRANSLATORS: command line option
                      help=_("set the screen reolsution to the given size id"))
    parser.add_option("-r", "--rate",
                      default=None,
                      action="store", type="int", dest="rate",
                      #TRANSLATORS: command line option
                      help=_("set the given refresh rate"))
    parser.add_option("-o", "--rotate",
                      default=None,
                      action="store", type="string", dest="rotate",
                      #TRANSLATORS: command line option
                      help=_("rotate the screen. supported values are "
                             "normal, left, inverted, right or 0, 90, 180, "
                             "270"))
    parser.add_option("--output", "",
                      default=None,
                      action="store", type="string", dest="output",
                      #TRANSLATORS: command line option
                      help=_("select an available output"))
    parser.add_option("--preferred", "",
                      action="store_true", dest="output_preferred",
                      #TRANSLATORS: command line option
                      help=_("choose the preferred resolution and rate"))
    parser.add_option("--mode", "",
                      action="store", type="int", dest="output_mode",
                      #TRANSLATORS: command line option
                      help=_("set to the mode of the given index number"))
    parser.add_option("--off", "",
                      action="store_true", dest="output_disable",
                      #TRANSLATORS: command line option
                      help=_("turn off the selected output"))
    parser.add_option("--left-of", "",
                      default=None,
                      action="store", type="string", dest="output_left",
                      #TRANSLATORS: command line option
                      help=_("move the output left of the given one"))
    parser.add_option("--right-of", "",
                      default=None,
                      action="store", type="string", dest="output_right",
                      #TRANSLATORS: command line option
                      help=_("move the output right of the given one"))
    parser.add_option("--above", "",
                      default=None,
                      action="store", type="string", dest="output_above",
                      #TRANSLATORS: command line option
                      help=_("move the output above of the given one"))
    parser.add_option("--below", "",
                      default=None,
                      action="store", type="string", dest="output_below",
                      #TRANSLATORS: command line option
                      help=_("move the output below of the given one"))
    parser.add_option("--same-as", "",
                      default=None,
                      action="store", type="string", dest="output_same",
                      #TRANSLATORS: command line option
                      help=_("move the output to the position of the "
                             "given one"))
    (options, args) = parser.parse_args()

    if xrandr.has_extension():
        if options.version:
            print "%x.%s" % xrandr.XRANDR_VERSION
            sys.exit()
        else:
            print _("XRandR %s.%s") % xrandr.XRANDR_VERSION
    else:
        print _("The XRandR extension is not available")
        sys.exit(1)

    changed_1_0 = False

    screen = xrandr.get_current_screen()

    if options.size != None:
        screen.set_size_index(options.size)
        changed_1_0 = True
    if options.rate:
        screen.set_refresh_rate(options.rate)
        changed_1_0 = True
    if options.rotate:
        if options.rotate in [_("normal"), "0"]:
            rotation = xrandr.RR_ROTATE_0
        elif options.rotate in [_("right"), "90"]:
            rotation = xrandr.RR_ROTATE_90
        elif options.rotate in [_("inverted"), "180"]:
            rotation = xrandr.RR_ROTATE_180
        elif options.rotate in [_("left"), "270"]:
            rotation = xrandr.RR_ROTATE_270
        else:
            print _("Invalid orientation")
            sys.exit(1)
        screen.set_rotation(rotation)
        changed_1_0 = True
    if changed_1_0:
        screen.apply_config()
    elif options.output:
        output = screen.get_output_by_name(options.output)
        if not output:
            print _("Output does not exist")
            sys.exit(1)
        if options.output_disable:
            output.disable()
        elif options.output_preferred:
            output.set_to_preferred_mode()
        elif options.output_mode != None:
            output.set_to_mode(options.output_mode)
        if options.output_left:
            output.set_relation(options.output_left, xrandr.RELATION_LEFT_OF)
        elif options.output_right:
            output.set_relation(options.output_right, xrandr.RELATION_RIGHT_OF)
        elif options.output_above:
            output.set_relation(options.output_above, xrandr.RELATION_ABOVE)
        elif options.output_below:
            output.set_relation(options.output_below, xrandr.RELATION_BELOW)
        elif options.output_same:
            output.set_relation(options.output_same, xrandr.RELATION_SAME_AS)
        screen.apply_output_config()
    else:
        screen.print_info(options.verbose)
Esempio n. 7
0
 def __init__(self):
     self.log = logging.getLogger('disper.switcher.xrandr')
     self.screen = xrandr.get_current_screen()
     if not xrandr.has_extension():
         raise Exception('No XRandR extension found')