mirror of
https://github.com/peter-tanner/wmctrl-for-windows.git
synced 2024-11-30 11:10:16 +08:00
Added -p and -b flag
This commit is contained in:
parent
dc0e1a5df9
commit
585a3c2a60
5
Makefile
5
Makefile
|
@ -2,7 +2,7 @@
|
||||||
CSC=csc
|
CSC=csc
|
||||||
CSC=mcs
|
CSC=mcs
|
||||||
|
|
||||||
PROG=wmctrl.exe
|
PROG=./wmctrl.exe
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,4 +15,5 @@ $(PROG): wmctrl.cs
|
||||||
test:
|
test:
|
||||||
$(PROG) -h
|
$(PROG) -h
|
||||||
$(PROG) -l
|
$(PROG) -l
|
||||||
$(PROG) -a gvim
|
$(PROG) -a devenv
|
||||||
|
#you can test the others yourself :D
|
||||||
|
|
14
README.md
14
README.md
|
@ -1,23 +1,27 @@
|
||||||
# wmctrl-for-windows
|
# wmctrl-for-windows
|
||||||
|
This is a fork of https://github.com/ebranlard/wmctrl-for-windows with two new flags added for PID and process title :D
|
||||||
|
|
||||||
Command line implementation of wmctrl for windows (pseudo-equivalent).
|
Command line implementation of wmctrl for windows (pseudo-equivalent).
|
||||||
Only few features of the linux tool wmctrl are implemented so far, that is:
|
Only few features of the linux tool wmctrl are implemented so far, that is:
|
||||||
- List the window titles, process name and ID
|
- List the window titles, process name and ID
|
||||||
- Switch the focus to a given window
|
- Switch the focus to a given window (Based on process title, process name or PID)
|
||||||
|
|
||||||
The program is written in C-sharp.
|
The program is written in C-sharp.
|
||||||
This repository contains the latest binary and the source code (compatible Mono or Microsoft).
|
This repository contains the latest binary and the source code (compatible Mono or Microsoft).
|
||||||
|
|
||||||
## Binaries
|
## Binaries
|
||||||
The latest binary is available [here](https://github.com/elmanuelito/wmctrl-for-windows/raw/master/_bin/wmctrl.exe)
|
You can get the binaries from the releases tab of this repo
|
||||||
|
|
||||||
## Features/ usage
|
## Features/ usage
|
||||||
|
|
||||||
usage: wmctrl [options] [args]
|
usage: wmctrl [options] [args]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-h : show this help
|
-h : show this help
|
||||||
-l : list windows
|
-l : list windows
|
||||||
-a <PNAME> : switch to the window of the process name <PNAME>
|
-a <PNAME> : switch to the window of the process name <PNAME>
|
||||||
|
-b <PTITLE> : switch to the window of the process title <PTITLE>
|
||||||
|
-p <PID> : switch to the window of the process ID <PID>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
82
wmctrl.cs
82
wmctrl.cs
|
@ -33,7 +33,63 @@ public class wmctrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
// --- Switch to Window (TITLE)
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public static int SwitchToWindowTitle(string procTitle)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
Process[] procs = Process.GetProcesses();
|
||||||
|
foreach (Process proc in procs)
|
||||||
|
{
|
||||||
|
if (! String.IsNullOrEmpty(proc.MainWindowTitle) && string.Compare(procTitle, proc.MainWindowTitle) == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Process Name: {0} ID: {1} Title: {2}", proc.ProcessName, proc.Id, proc.MainWindowTitle);
|
||||||
|
SwitchToThisWindow(proc.MainWindowHandle); //Just going to use the first window as per usual
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == -1)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: No process found for title: {0}", procTitle);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
// --- Switch to Window (PID)
|
||||||
|
// --------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public static int SwitchToWindowPID(string procPIDstr)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
int procPID;
|
||||||
|
if (Int32.TryParse(procPIDstr, out procPID)){
|
||||||
|
Process[] procs = Process.GetProcesses();
|
||||||
|
foreach (Process proc in procs)
|
||||||
|
{
|
||||||
|
if (procPID == proc.Id) //Can processes have no PID in MS windows? I have no idea.
|
||||||
|
{
|
||||||
|
Console.WriteLine("Process Name: {0} ID: {1} Title: {2}", proc.ProcessName, proc.Id, proc.MainWindowTitle);
|
||||||
|
SwitchToThisWindow(proc.MainWindowHandle); //Just going to use the first window as per usual
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret == -1)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: No process found for PID: {0}", procPIDstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: Invalid PID: {0}", procPIDstr);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------
|
||||||
// --- List Windows info
|
// --- List Windows info
|
||||||
// --------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------
|
||||||
|
@ -59,9 +115,11 @@ public class wmctrl
|
||||||
Console.WriteLine("usage: wmctrl [options] [args]");
|
Console.WriteLine("usage: wmctrl [options] [args]");
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("options:");
|
Console.WriteLine("options:");
|
||||||
Console.WriteLine(" -h : show this help");
|
Console.WriteLine(" -h : show this help");
|
||||||
Console.WriteLine(" -l : list windows");
|
Console.WriteLine(" -l : list windows");
|
||||||
Console.WriteLine(" -a <PNAME> : switch to the window of the process name <PNAME>");
|
Console.WriteLine(" -a <PNAME> : switch to the window of the process name <PNAME>");
|
||||||
|
Console.WriteLine(" -b <PTITLE> : switch to the window of the process title <PTITLE>");
|
||||||
|
Console.WriteLine(" -p <PID> : switch to the window of the process ID <PID>");
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -99,6 +157,24 @@ public class wmctrl
|
||||||
status=-1;
|
status=-1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "-b": // Switch to window (TITLE)
|
||||||
|
if (i+1<nArgs) {
|
||||||
|
status=SwitchToWindowTitle(args[i+1]);
|
||||||
|
i=i+2;
|
||||||
|
}else{
|
||||||
|
Console.WriteLine("Error: command line option -a needs to be followed by a process title.");
|
||||||
|
status=-1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "-p": // Switch to window (PID)
|
||||||
|
if (i+1<nArgs) {
|
||||||
|
status=SwitchToWindowPID(args[i+1]);
|
||||||
|
i=i+2;
|
||||||
|
}else{
|
||||||
|
Console.WriteLine("Error: command line option -a needs to be followed by a process ID.");
|
||||||
|
status=-1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "-l": // List Windows
|
case "-l": // List Windows
|
||||||
status=ListWindows();
|
status=ListWindows();
|
||||||
i++;
|
i++;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user