Sunday, May 22, 2016

Pixel Grabber (coordinate and pixel color info at mouse position - utility written in AHK)

Pixel Grabber V1.0



If you are a graphic designer then you may be familiar with ColorPic or Gpic; for those of you who aren't familiar with those programs (or other alternatives) these are color picker  and swatch programs (Gpic can convert PS .ase to GIMP .gpl and vice versa) that are great for retrieving color and some window info at the mouse cursor.

There are quite a few decent alternatives out there, but I wanted something more tailored to my needs since not only do I do graphic design, but I also build lots of GUI's in AutoHotkey and so I wrote a utility that is great for graphic design, but also good for building AHK GUI's.

Pixel Grabber V1.0 is a small utility that retrieves coordinate and color information at the mouse cursor simply by holding the Contol key and left clicking (Ctrl+Left Click). For now the information retrieved is the Windows title (not all windows have names), the Screen (Desktop) and Client  (if exists) coordinates relative to the each, and the actual pixels color with the code and a preview of the color. All information is copied to the clipboard in subsequent order, but the clipboards contents can be cleared with a button.

Downloads

Copyright Ian Pride 2016 © This program is distributed under the terms of the GNU General Public License.

Your choice of just the portable executable or the zip package which inludes the executable, source code, and a copy of the license:

Source Script (needs AHK, use the exe to use without install)

; Name:   Pixel Grabber V1.0 
; Author: Lateralus138 (A.K.A Flux Apex A.K.A Ian Pride)
; Year: 2016
; Copyright Ian Pride 2016 © This program is distributed under the terms of the GNU General Public License.
; Email: faithnomoread@yahoo.com
; http://www.gnu.org/licenses/gpl-3.0.en.html
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see .
;
; Gets window and color information at pixel coordinate 
; with the hotkeys: Ctrl+LeftClick. Very useful for 
; graphic design or writing AutoHotkey GUIs. 
; 
OnMessage(0x20, "WM_SETCURSOR")
#SingleInstance, Force
Menu, Tray, NoStandard
Menu, Tray, Add, &Help, gsHlp
Menu, Tray, Add, My &Blog, gsMBlg 
Menu, Tray, Add
Menu, Tray, Add, E&xit, gsExt
_fGtMn()
GuiControl, Show, gsRstClp %But%
Return
;End auto-execute

;Hotkeys
+Esc::Reload
^LButton::_fGtInf(_vX, _vY,_vRgb,_vBgr, _vWx, _vWy, _vWt, _vWw, _vWh, _vXc, _vYc)
;Gosubs
gsMBlg:
 Run, "http://agnosticmicrocosm.blogspot.com/"
Return
gsHlp:
 MsgBox,64,Pixel Grabber Help, % "To use this simply hold Ctrl & left click the place you"
  . "`nwant the coordinates & color of. Coordinates & color" 
  . "`nwill be displayed & copied to your clipboard. Multiple" 
  . "`ninfo boxes can be left open and subsequent new" 
  . "`ncoordinates & colors will be added to the clipboard" 
  . "`nstack."
Return
gsHide:
 Gui, Cancel
Return
MainGuiEscape:
 Gosub, gsHide
Return
gsRstClp:
 clipboard =
Return

;Functions
MouseOver(_vXa, _vYa, _vXb, _vYb)
{
 MouseGetPos, _vPx, _vPy
 _vDtct := _vPx >= _vXa AND _vPx <= _vXb AND _vPy >= _vYa AND _vPy <= _vYb
 Return _vDtct
}
WM_SETCURSOR(){
 Loop
  {
   If MouseOver(0, 0, 250, 344) {
    If Not hCursor1 { 
      hCursor1 := DllCall("LoadCursor", "uint", 0, "uint", 32512)
     }
    DllCall("SetCursor", "uint", hCursor1)
    ;Return True
   } 
   If MouseOver(135, 164, 247, 186) Or MouseOver(135, 190, 247, 212) Or MouseOver(135, 216, 247, 238) Or MouseOver(135, 242, 247, 264) {
    If Not hCursor2 { 
      hCursor2 := DllCall("LoadCursor", "uint", 0, "uint", 32649)
     }
    DllCall("SetCursor", "uint", hCursor2)
    Return True
   }
   GuiControl, Show, gsHlp %But%
   Break
  }
 Return
}
WM_SETCURSOR2(){
 Loop
  {
   IfWinActive, Pixel Grabber Info 
   {
    If MouseOver(20, 81, 66, 129) Or  MouseOver(256, 99, 290, 114) {
     If Not hCursor2 { ;Make sure the cursor is already loaded 
       hCursor2 := DllCall("LoadCursor", "uint", 0, "uint", 32649)
      }
     DllCall("SetCursor", "uint", hCursor2)
     Return True ;Stop further processing
    }  
   }
  }
 Return
}

_fGtInf(ByRef _vX, ByRef _vY, ByRef _vRgb, ByRef _vBgr, ByRef _vWx, ByRef _vWy, ByRef _vWt, ByRef _vWw, ByRef  _vWh, ByRef _vXc, ByRef _vYc){
 OnMessage(0x20, "WM_SETCURSOR2")
 CoordMode, Mouse, Screen
 MouseGetPos, _vX, _vY
 MouseGetPos,,,_vWPn
 WinActivate, ahk_id %_vWPn%
 CoordMode, Mouse, Window
 MouseGetPos, _vXc, _vYc
 WinGetActiveStats, _vWt, _vWw, _vWh, _vWx, _vWy
 If (_vWx = "-5"){
  _vWx := "0"
  _vXc := _vXc - 5
 }
 If (_vWy = "-5"){
  _vWy := "0"
  _vYc := _vYc - 5
 }
 CoordMode, Pixel, Screen
 PixelGetColor, _vRgb , %_vX%, %_vY%,RGB
 PixelGetColor, _vBgr , %_vX%, %_vY%
 clipboard := clipboard "`nWindow Name: `n" _vWt "`nDesktop Relative:`nx" _vX " y" _vY "`nWindow Relative: `nx" _vXc " y" _vYc "`nColor at coordinate: `n" _vRgb "`n"
 Gui, New
 Gui, Add, Text, w300+BackgroundTrans, % "Active Window Name:`n" 
  . _vWt
  . "`n`nWindow upper left starting position: `nx: "
  . _vWx "        |     y: " _vWy 
  . "`n`nDesktop relative coordinates at mouse position:`nx: " 
  . _vX "        |     y: " _vY 
  . "`n`nWindow relative coordinates at mouse position:`nx: " 
  . _vXc "        |     y:" _vYc 
  . "`n`nCoordinates and color have been copied to your clipboard." 
 Gui, Add, Progress, xp+5 yp+186 w50 h50 c%_vRgb%,100
 StringReplace, _vRgb, _vRgb, 0x,
 Gui, Add, Text, +BackgroundTrans xp+60 yp+18, % "Color at mouse postion: " . _vRgb
 Gui, Add, Button, xp+175 yp-2 ggsHide, Close
 Gui, Show,w300 ,Pixel Grabber Info
 Return
}
WM_MOUSELEAVE(){
}
_fGtMn(){

 OnMessage(0x20, "WM_SETCURSOR")
 Gui, New
 Gui, Main: Default
 Gui, Font, s8, Cambria
 _fGrphx("125","0","66","100","125","125","EF7D1A","2","2")
 _fGrphx("0","125","66","100","125","125","EF7D1A","2","2")
 _fGrphx("0","0","66","100","125","125","7DA485","2","2")
 _fTxtBrdr("Pixel","16","0","EF7D1A","white","28")
 _fTxtBrdr("Grabber","100","0","7DA485","white","28")
 Gui, Font, s11, Cambria
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y141  w112 h22, 100
 _fTxtBrdr2("Reset Clipboard","112","22", "gsRstClp","135","141","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y167  w112 h22, 100
 _fTxtBrdr2("Help","112","22","gsHlp","135","167","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y193  w112 h22, 100
 _fTxtBrdr2("My Blog","112","22","gsMBlg","135","193","7DA485","White","11")
 Gui, Main: Add, Progress, -Smooth Disabled cEF7D1A Background3F3F3F x135  y219  w112 h22, 100
 _fTxtBrdr2("Exit","112","22","gsExt","135","219","7DA485","White","11")
 Gui, Main: Show, w250 h250 Center, Pixel Grabber
 Return
}
_fGrphx(_vCntrX, _vCntrY, _vLp, _vLpWdth, _vWdth, _vHght, _vClr, _vIncrA, _vIncrB, _vBgClrb := "White"){
 Loop, %_vLp%
  { 
   Gui, Main: Add, Progress, -Smooth Disabled x%_vCntrX% y%_vCntrY% w%_vWdth% h%_vHght% Background%_vBgClrb% c%_vClr%, % _vLpWdth
   _vCntrX := _vCntrX + _vIncrA
   _vCntrY := _vCntrY + _vIncrB
  }
 Return
}
_fTxtBrdr(_vTxt, _vXb := "0", _vYb := "0", _vBgClr := "Black", _vClr := "White", _vTxtSz := "8"){
 Gui, Font, q5 s%_vTxtSz%, Cambria
 Gui, Main: Add, Text, +BackgroundTrans x%_vXb% y%_vYb% c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp yp+2 c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp+2 yp c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp yp-2 c%_vBgClr%, % _vTxt
 Gui, Main: Add, Text, +BackgroundTrans xp-1 yp+1 c%_vClr%, % _vTxt
 Return
}
_fTxtBrdr2(_vTxt2, _vXw, _vYw, _vGs, _vXb2 := "0", _vYb2 := "0", _vBgClr2 := "Black", _vClr2 := "White", _vTxtSz2 := "8"){
 Gui, Font, q5 s%_vTxtSz2%, Cambria
 Gui, Main: Add, Text, +Center +BackgroundTrans x%_vXb2% y%_vYb2% w%_vXw% h%_vYw% c%_vBgClr2%, %_vTxt2%
 Gui, Main: Add, Text, +Center +BackgroundTrans xp yp+2 w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp+2 yp w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp yp-2 w%_vXw% h%_vYw% c%_vBgClr2%, % _vTxt2
 Gui, Main: Add, Text, +Center +BackgroundTrans xp-1 yp+1 w%_vXw% h%_vYw% c%_vClr2% g%_vGs%, % _vTxt2
 Return
}
GuiClose:
 Gui, Cancel
Return
gsExt:
MainGuiClose:
 SplashTextOn, 200, 22, ,% "Exiting Pixel Grabber!!!"
 Sleep 1500
 ExitApp
 
 

Wednesday, May 18, 2016

Linux window shading with wmctrl (toggle all windows script)


Wmctrl shade toggle script for Linux



Linux Windows Management

If you use Linux then you may be familiar with and/or love the fact that it has the most amazing and arguably best window management systems compared to Windows or Mac (both of which you only have one choice). In Linux there are various WM (Window Management) systems you can use and most can be used in lots of Linux distributions (Debian, Mint, Opensuse, etc...) depending on the WM.

One nice feature of some WM's is the shading/rollup feature, which instead of minimizing a window you can just hit the shade button and it will be rolled up to a just a thin title bar allowing you to see more of your desktop and/or other windows, but being reminded that window is open and you have stuff left to do there. This feature usually works well in most distros, but not always and not always well in every application type. In Ubuntu which is one of the biggest distros this ability has been ruined by the unity compiz plugin and so any window shading will now just minimize the window. This is, of course, if you use Unity as your WM.

WMCTRL

If you do have issues with normal window shading buttons (Opensuse has some issues) or normal hotkeys not executing shading then you can almost always write a simple shell script using wmctrl:

            wmctrl -r :ACTIVE: -b toggle,shaded
        

If you call this simple script using a hotkey this will shade whatever window is is currently active. You can also toggle the shade state of a specific window. By using wmctrl -l you can list all active windows and get the names and ids of each. Using the window name you can then do this:

wmctrl -l # <- lists all windows

    # E.g:
    #0x03600017 -1         N/A Desktop — Plasma
    #0x0360001a -1         N/A Plasma
    #0x03600025 -1         N/A Plasma
    #0x01800001  1 fluxinferno Blogger: The Agnostic Microcosm - Edit post - Google Chrome
    #0x0500002b -1 fluxinferno Guake!
    # then with the window title you can toggle its' shaded state with:

wmctrl -r "Google Chrome" -b toggle,shaded
        
WMCTRL comes already pre-installed in most distros, but I am pretty sure it can be found for almost any distro you can imagine if not.

Wmctrl to toggle shade state of all windows

Sometimes you may just want to toggle the shade states of all windows. That gets a little tricker as you have to list all windows currently running, store the window names and and run the above command on each name. This can be done using a for loop on the list command. The below code can be run from your terminal, but is better used in a script and set to run with a hotkey. I usually use Alt+X to toggle active and Ctrl+Alt+X to toggle all. Check out this shell script to toggle shade on all windows:

for i in $(wmctrl -l | awk '{print $4}'); do
  wmctrl -r "$i" -b toggle,shaded
done
        

Just save the above script to a file and make sure it's executable and place it in any folder your shells PATH is read from. Then set a hotkey to the script and execute as needed.