ARCHLabs - Hot Corners

A place to share tips, guides, application configurations and scripts about all elements of ArchLabs

Moderator: Founder

ARCHLabs - Hot Corners

PostPosted by natemaia » Mon May 08, 2017 8:04 pm

Hello
First off you will need to install a few packages

Code: Select all
sudo pacman -S xdo xdotool python-xlib python2-xlib --needed


Now thats in order we need to make a file in /usr/bin and name it AL-hotcorners

Code: Select all
sudo nano /usr/bin/AL-hotcorners


Simply Copy-Paste

Code: Select all
#!/usr/bin/env python2
# AL-hotcorners:
# A script for adding hot corners to Openbox.
# Written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough <corenominal@corenominal.org>
# ----------------------------------------------------------------------
# License:
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#                    Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#
# Mildly modified to fit ARCHLabs naming scheme and to abide by Philip's rules
# ----------------------------------------------------------------------

from Xlib import display
from Xlib.ext.xtest import fake_input
from Xlib import X
from subprocess import Popen, PIPE, STDOUT
import sys, time, os, ConfigParser, re

check_intervall = 0.08

p = Popen(['xdotool','getdisplaygeometry'], stdout=PIPE, stderr=STDOUT)
Dimensions = p.communicate()
Dimensions = Dimensions[0].replace('\n', '')
Dimensions = Dimensions.split(' ')
width = int(Dimensions[0])
height = int(Dimensions[1])
hw = width / 2
rt = width - 1
bt = height - 1

def print_usage():
   print "AL-hotcorners: usage:"
   print "  --help          show this message and exit"
   print "  --kill          attempt to kill any running instances"
   print "  --daemon        run daemon and listen for cursor triggers"
   print ""
   exit()

if len(sys.argv) < 2 or sys.argv[1] == "--help":
   print_usage()

elif sys.argv[1] == "--kill":
   print "Attempting to kill any running instances..."
   os.system('pkill -9 -f AL-hotcorners')
   exit()

elif sys.argv[1] == "--daemon":
   Config = ConfigParser.ConfigParser()
   cfgdir = os.getenv("HOME")+"/.config/AL-hotcorners"
   rcfile = cfgdir+"/AL-hotcornersrc"
   bounce = 2
   disp = display.Display()
   root=display.Display().screen().root

   def mousepos():
      data = root.query_pointer()._data
      return data["root_x"], data["root_y"], data["mask"]

   def mousemove(x, y):
      fake_input(disp, X.MotionNotify, x=x, y=y)
      disp.sync()

   try:
      cfgfile = open(rcfile)
   except IOError as e:
      if not os.path.exists(cfgdir):
         os.makedirs(cfgdir)
      cfgfile = open(rcfile,'w')
      Config.add_section('Hot Corners')
      Config.set('Hot Corners','top_left_corner_command', 'gmrun')
      Config.set('Hot Corners','top_right_corner_command', '')
      Config.set('Hot Corners','bottom_left_corner_command', '')
      Config.set('Hot Corners','bottom_right_corner_command', '')
      Config.write(cfgfile)
      cfgfile.close()

   while True:
      Config.read(rcfile)
      time.sleep(check_intervall)
      pos = mousepos()
     
      if pos[0] == 0 and pos[1] == 0:   
         if Config.get('Hot Corners','top_left_corner_command') != '':
            time.sleep(0.2)
            pos = mousepos()
            if pos[0] == 0 and pos[1] == 0:
               mousemove(pos[0] + bounce, pos[1] + bounce)
               os.system('(' + Config.get('Hot Corners','top_left_corner_command') + ') &')
               mousemove(pos[0] + bounce, pos[1] + bounce)
               time.sleep(0.1)
     
      elif pos[0] == rt and pos[1] == 0:
         if Config.get('Hot Corners','top_right_corner_command') != '':
            time.sleep(0.2)
            pos = mousepos()
            if pos[0] == rt and pos[1] == 0 :
               mousemove(pos[0] - bounce, pos[1] + bounce)
               os.system('(' + Config.get('Hot Corners','top_right_corner_command') + ') &')
               mousemove(pos[0] - bounce, pos[1] + bounce)
               time.sleep(0.1)

      elif pos[0] == 0 and pos[1] == bt:
         if Config.get('Hot Corners','bottom_left_corner_command') != '':
            time.sleep(0.2)
            pos = mousepos()
            if pos[0] == 0 and pos[1] == bt:
               mousemove(pos[0] + bounce, pos[1] - bounce)
               os.system('(' + Config.get('Hot Corners','bottom_left_corner_command') + ') &')
               mousemove(pos[0] + bounce, pos[1] - bounce)
               time.sleep(0.1)

      elif pos[0] == rt and pos[1] == bt:
         if Config.get('Hot Corners','bottom_right_corner_command') != '':
            time.sleep(0.2)
            pos = mousepos()
            if pos[0] == rt and pos[1] == bt:
               mousemove(pos[0] - bounce, pos[1] - bounce)
               os.system('(' + Config.get('Hot Corners','bottom_right_corner_command') + ') &')
               mousemove(pos[0] - bounce, pos[1] - bounce)
               time.sleep(0.1)

else:
   print_usage()


Ctrl+x answer y then hit enter to save and exit

Then we need to make it executable

Code: Select all
sudo chmod +x /usr/bin/AL-hotcorners


Now all of the root stuff is finished, next we need to make the config folder

Code: Select all
mkdir ~/.config/AL-hotcorners


Create a config file (its needed to make our own custom commands for each corner)

Code: Select all
nano ~/.config/AL-hotcorners/AL-hotcornersrc


Copy-Paste

Code: Select all
[Hot Corners]
top_left_corner_command = gmrun
top_right_corner_command =
bottom_left_corner_command = termite
bottom_right_corner_command =

^^^ This can be edited to run whatever you want ive included gmrun and termite, being the default in ARCHLabs (i also like kupfer)

Almost done!! Lastly we want to add it to autostart

Code: Select all
nano ~/.config/openbox/autostart


Add to the bottom of the file

Code: Select all
(sleep 1; AL-hotcorners --daemon) &


Please let me know what you think as i know these kinds of additions aren't for everyone, but im really liking it :D
This could be a bit shorter, I just wanted to be able to open a single terminal anywhere and in a matter of a few minutes be finished :geek:
I did not write the original cb-hotcorners i simply modified it to fit archlabs, all credit goes to Philip Newborough
User avatar
natemaia
ArchLabs Guru
ArchLabs Guru
 
Posts: 75
Joined: Thu Mar 16, 2017 10:14 pm
Location: Canada - British Columbia
Running Release: 5.0

Re: ARCHLabs - Hot Corners

PostPosted by erikdubois » Tue May 09, 2017 5:36 am

adding it to the github as https://github.com/ARCHLabs/Archlabs-Pipemenus/issues/4
thanks for posting
we have indeed still a lot of pipemenu's that we can use
Living to learn, learning to live.
Linux fits well in my life's motto.
More info on http://erikdubois.be
Archlabs support articles are on https://goo.gl/AaYI0b
Archlabs support youtube channel is on https://goo.gl/Lovquv
User avatar
erikdubois
Site Admin
Site Admin
 
Posts: 333
Joined: Sun Mar 05, 2017 5:42 am
Location: Belgium

Re: ARCHLabs - Hot Corners

PostPosted by Dobbie03 » Tue May 09, 2017 5:35 pm

Thanks for the tutorial, very helpful.
I like my Metal like my coffee.......black
User avatar
Dobbie03
Founder
Founder
 
Posts: 549
Joined: Sat Feb 18, 2017 2:51 pm
Location: New Zealand
Running Release: DobbieBang

Re: ARCHLabs - Hot Corners

PostPosted by ector » Wed Jun 14, 2017 9:50 pm

best tutorial thank @matemaia :D
ector
 
Posts: 23
Joined: Thu Jun 01, 2017 6:14 am


Return to Configs, Scripts, Tutorials and Tips

Who is online

Users browsing this forum: No registered users and 0 guests