mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
Merge pull request #231 from go-vgo/dev
update go mod pkg and remove vendor
This commit is contained in:
commit
c7dee954e5
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,6 +44,7 @@ _testmain.go
|
||||
#
|
||||
cdeps/hook
|
||||
event/hook
|
||||
vendor
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
|
16
go.mod
16
go.mod
@ -1,25 +1,21 @@
|
||||
module github.com/go-vgo/robotgo
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||
github.com/lxn/win v0.0.0-20190905152257-9739bfe37f9b
|
||||
github.com/lxn/win v0.0.0-20190910083938-ae3bd9765f46
|
||||
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
|
||||
github.com/otiai10/gosseract v2.2.1+incompatible
|
||||
github.com/robotn/gohook v0.0.0-20190905174353-5bea7a10cc3a
|
||||
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934
|
||||
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770
|
||||
github.com/stretchr/testify v1.3.0 // indirect
|
||||
github.com/vcaesar/gops v0.0.0-20190812170137-58fea72d948e
|
||||
github.com/vcaesar/gops v0.0.0-20190910162627-58ac09d12a53
|
||||
github.com/vcaesar/imgo v0.0.0-20190523174309-2cf5275c2a13
|
||||
github.com/vcaesar/tt v0.0.0-20190713164158-ecee6bc61ac7
|
||||
golang.org/x/image v0.0.0-20190902063713-cb417be4ba39
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8 // indirect
|
||||
)
|
||||
|
||||
//golang.org/x/image => github.com/golang/image v0.0.0-20181116024801-cd38e8056d9b
|
||||
//replace golang.org/x/sys => github.com/golang/sys v0.0.0-20190109145017-48ac38b7c8cb
|
||||
replace github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802 => github.com/BurntSushi/xgb 27f122750802
|
||||
|
||||
go 1.13
|
||||
|
27
go.sum
27
go.sum
@ -1,9 +1,7 @@
|
||||
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
|
||||
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802 h1:otE7gFP0KwnPTKtMvPLOcWDZxx6rXYyJGlrXbhoD7og=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e h1:4ZrkT/RzpnROylmoQL57iVUL57wGKTR5O6KpVnbm2tA=
|
||||
github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e/go.mod h1:uw9h2sd4WWHOPdJ13MQpwK5qYWKYDumDqxWWIknEQ+k=
|
||||
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
|
||||
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
|
||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
@ -14,8 +12,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
|
||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/lxn/win v0.0.0-20190905152257-9739bfe37f9b h1:MA/z1Lrrp+AE+IBhp9ztPTw42sNPSpAZO+FHKElCJ8M=
|
||||
github.com/lxn/win v0.0.0-20190905152257-9739bfe37f9b/go.mod h1:oO6+4g3P1GcPAG7LPffwn8Ye0cxW0goh0sUZ6+lRFPs=
|
||||
github.com/lxn/win v0.0.0-20190910083938-ae3bd9765f46 h1:irZ+wYKCpwPPsAhaIl4r89ZMCE0pRvgtnrl0EYP0Ps0=
|
||||
github.com/lxn/win v0.0.0-20190910083938-ae3bd9765f46/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
|
||||
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95 h1:+OLn68pqasWca0z5ryit9KGfp3sUsW4Lqg32iRMJyzs=
|
||||
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
|
||||
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 h1:o59bHXu8Ejas8Kq6pjoVJQ9/neN66SM8AKh6wI42BBs=
|
||||
@ -28,6 +26,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/robotn/gohook v0.0.0-20190905174353-5bea7a10cc3a h1:mO88NwjGgGRLCo5HuXqjewR/m294XJ0OcyqRmhtl2d4=
|
||||
github.com/robotn/gohook v0.0.0-20190905174353-5bea7a10cc3a/go.mod h1:YD5RyCnUEY2xqtkkgeQVZ31UAfAnVPwUxpTE5cwSXg4=
|
||||
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 h1:2lhSR8N3T6I30q096DT7/5AKEIcf1vvnnWAmS0wfnNY=
|
||||
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934/go.mod h1:SxQhJskUJ4rleVU44YvnrdvxQr0tKy5SRSigBrCgyyQ=
|
||||
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 h1:2uX8QRLkkxn2EpAQ6I3KhA79BkdRZfvugJUzJadiJwk=
|
||||
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770/go.mod h1:svkDXUDQjUiWzLrA0OZgHc4lbOts3C+uRfP6/yjwYnU=
|
||||
github.com/shirou/gopsutil v2.19.6+incompatible h1:49/Gru26Lne9Cl3IoAVDZVM09hvkSrUodgIIsCVRwbs=
|
||||
github.com/shirou/gopsutil v2.19.6+incompatible/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U=
|
||||
@ -36,20 +38,23 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/vcaesar/gops v0.0.0-20190812170137-58fea72d948e h1:FsXjVgofw69zYVU0J/8RYKpKVQ7lkU5AWWFRK3QITFU=
|
||||
github.com/vcaesar/gops v0.0.0-20190812170137-58fea72d948e/go.mod h1:J9SDgZxjSePEBlF0yG9NjHftBbybmRPhLZIDbJz83Fw=
|
||||
github.com/vcaesar/gops v0.0.0-20190910162627-58ac09d12a53 h1:tYb/9KQi8dTCSDia2NwbuhUbKlaurqC/S7MFQo96nLk=
|
||||
github.com/vcaesar/gops v0.0.0-20190910162627-58ac09d12a53/go.mod h1:5txYrXKrQG6ZJYdGIiMVVxiOhbdACnwBcHzIwGQ7Nkw=
|
||||
github.com/vcaesar/imgo v0.0.0-20190523174309-2cf5275c2a13 h1:BsisshViEpto+nl0UUMo06z9LmsgLKCRrJDAmN+wzLo=
|
||||
github.com/vcaesar/imgo v0.0.0-20190523174309-2cf5275c2a13/go.mod h1:D+Ywq+8bsOIg4nUk1lgHtPGxYxknhySi/HfZjG7VN/g=
|
||||
github.com/vcaesar/tt v0.0.0-20190713164158-ecee6bc61ac7 h1:a64ynLITFRQwdt9zAYtVN2AJuJHq0Mr7pYTtyKrGwFk=
|
||||
github.com/vcaesar/tt v0.0.0-20190713164158-ecee6bc61ac7/go.mod h1:xKkGp+ufbz/1DQmNxdbAMFqZJOVIJEX7dGvLZMhPIWg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/image v0.0.0-20190902063713-cb417be4ba39 h1:4dQcAORh9oYBwVSBVIkP489LUPC+f1HBkTYXgmqfR+o=
|
||||
golang.org/x/image v0.0.0-20190902063713-cb417be4ba39/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a h1:gHevYm0pO4QUbwy8Dmdr01R5r1BuKtfYqRqF0h/Cbh0=
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b h1:3S2h5FadpNr0zUUCVZjlKIEYF+KaX/OBplTGo89CYHI=
|
||||
golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8 h1:41hwlulw1prEMBxLQSlMSux1zxJf07B3WPsdjJlKZxE=
|
||||
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -16,9 +16,9 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
"github.com/BurntSushi/xgbutil/ewmh"
|
||||
"github.com/robotn/xgb/xproto"
|
||||
"github.com/robotn/xgbutil"
|
||||
"github.com/robotn/xgbutil/ewmh"
|
||||
)
|
||||
|
||||
var xu *xgbutil.XUtil
|
||||
|
2
vendor/github.com/BurntSushi/xgb/.gitignore
generated
vendored
2
vendor/github.com/BurntSushi/xgb/.gitignore
generated
vendored
@ -1,2 +0,0 @@
|
||||
xgbgen/xgbgen
|
||||
.*.swp
|
18
vendor/github.com/BurntSushi/xgb/AUTHORS
generated
vendored
18
vendor/github.com/BurntSushi/xgb/AUTHORS
generated
vendored
@ -1,18 +0,0 @@
|
||||
Andrew Gallant is the maintainer of this fork. What follows is the original
|
||||
list of authors for the x-go-binding.
|
||||
|
||||
# This is the official list of XGB authors for copyright purposes.
|
||||
# This file is distinct from the CONTRIBUTORS files.
|
||||
# See the latter for an explanation.
|
||||
|
||||
# Names should be added to this file as
|
||||
# Name or Organization <email address>
|
||||
# The email address is not required for organizations.
|
||||
|
||||
# Please keep the list sorted.
|
||||
|
||||
Anthony Martin <ality@pbrane.org>
|
||||
Firmansyah Adiputra <frm.adiputra@gmail.com>
|
||||
Google Inc.
|
||||
Scott Lawrence <bytbox@gmail.com>
|
||||
Tor Andersson <tor.andersson@gmail.com>
|
39
vendor/github.com/BurntSushi/xgb/CONTRIBUTORS
generated
vendored
39
vendor/github.com/BurntSushi/xgb/CONTRIBUTORS
generated
vendored
@ -1,39 +0,0 @@
|
||||
Andrew Gallant is the maintainer of this fork. What follows is the original
|
||||
list of contributors for the x-go-binding.
|
||||
|
||||
# This is the official list of people who can contribute
|
||||
# (and typically have contributed) code to the XGB repository.
|
||||
# The AUTHORS file lists the copyright holders; this file
|
||||
# lists people. For example, Google employees are listed here
|
||||
# but not in AUTHORS, because Google holds the copyright.
|
||||
#
|
||||
# The submission process automatically checks to make sure
|
||||
# that people submitting code are listed in this file (by email address).
|
||||
#
|
||||
# Names should be added to this file only after verifying that
|
||||
# the individual or the individual's organization has agreed to
|
||||
# the appropriate Contributor License Agreement, found here:
|
||||
#
|
||||
# http://code.google.com/legal/individual-cla-v1.0.html
|
||||
# http://code.google.com/legal/corporate-cla-v1.0.html
|
||||
#
|
||||
# The agreement for individuals can be filled out on the web.
|
||||
#
|
||||
# When adding J Random Contributor's name to this file,
|
||||
# either J's name or J's organization's name should be
|
||||
# added to the AUTHORS file, depending on whether the
|
||||
# individual or corporate CLA was used.
|
||||
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
|
||||
# Please keep the list sorted.
|
||||
|
||||
Anthony Martin <ality@pbrane.org>
|
||||
Firmansyah Adiputra <frm.adiputra@gmail.com>
|
||||
Ian Lance Taylor <iant@golang.org>
|
||||
Nigel Tao <nigeltao@golang.org>
|
||||
Robert Griesemer <gri@golang.org>
|
||||
Russ Cox <rsc@golang.org>
|
||||
Scott Lawrence <bytbox@gmail.com>
|
||||
Tor Andersson <tor.andersson@gmail.com>
|
42
vendor/github.com/BurntSushi/xgb/LICENSE
generated
vendored
42
vendor/github.com/BurntSushi/xgb/LICENSE
generated
vendored
@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2009 The XGB Authors. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Subject to the terms and conditions of this License, Google hereby
|
||||
// grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
||||
// royalty-free, irrevocable (except as stated in this section) patent
|
||||
// license to make, have made, use, offer to sell, sell, import, and
|
||||
// otherwise transfer this implementation of XGB, where such license
|
||||
// applies only to those patent claims licensable by Google that are
|
||||
// necessarily infringed by use of this implementation of XGB. If You
|
||||
// institute patent litigation against any entity (including a
|
||||
// cross-claim or counterclaim in a lawsuit) alleging that this
|
||||
// implementation of XGB or a Contribution incorporated within this
|
||||
// implementation of XGB constitutes direct or contributory patent
|
||||
// infringement, then any patent licenses granted to You under this
|
||||
// License for this implementation of XGB shall terminate as of the date
|
||||
// such litigation is filed.
|
78
vendor/github.com/BurntSushi/xgb/Makefile
generated
vendored
78
vendor/github.com/BurntSushi/xgb/Makefile
generated
vendored
@ -1,78 +0,0 @@
|
||||
# This Makefile is used by the developer. It is not needed in any way to build
|
||||
# a checkout of the XGB repository.
|
||||
# It will be useful, however, if you are hacking at the code generator.
|
||||
# i.e., after making a change to the code generator, run 'make' in the
|
||||
# xgb directory. This will build xgbgen and regenerate each sub-package.
|
||||
# 'make test' will then run any appropriate tests (just tests xproto right now).
|
||||
# 'make bench' will test a couple of benchmarks.
|
||||
# 'make build-all' will then try to build each extension. This isn't strictly
|
||||
# necessary, but it's a good idea to make sure each sub-package is a valid
|
||||
# Go package.
|
||||
|
||||
# My path to the X protocol XML descriptions.
|
||||
XPROTO=/usr/share/xcb
|
||||
|
||||
# All of the XML files in my /usr/share/xcb directory EXCEPT XKB. -_-
|
||||
# This is intended to build xgbgen and generate Go code for each supported
|
||||
# extension.
|
||||
all: build-xgbgen \
|
||||
bigreq.xml composite.xml damage.xml dpms.xml dri2.xml \
|
||||
ge.xml glx.xml randr.xml record.xml render.xml res.xml \
|
||||
screensaver.xml shape.xml shm.xml xc_misc.xml \
|
||||
xevie.xml xf86dri.xml xf86vidmode.xml xfixes.xml xinerama.xml \
|
||||
xprint.xml xproto.xml xselinux.xml xtest.xml \
|
||||
xvmc.xml xv.xml
|
||||
|
||||
build-xgbgen:
|
||||
(cd xgbgen && go build)
|
||||
|
||||
# Builds each individual sub-package to make sure its valid Go code.
|
||||
build-all: bigreq.b composite.b damage.b dpms.b dri2.b ge.b glx.b randr.b \
|
||||
record.b render.b res.b screensaver.b shape.b shm.b xcmisc.b \
|
||||
xevie.b xf86dri.b xf86vidmode.b xfixes.b xinerama.b \
|
||||
xprint.b xproto.b xselinux.b xtest.b xv.b xvmc.b
|
||||
|
||||
%.b:
|
||||
(cd $* ; go build)
|
||||
|
||||
# Installs each individual sub-package.
|
||||
install: bigreq.i composite.i damage.i dpms.i dri2.i ge.i glx.i randr.i \
|
||||
record.i render.i res.i screensaver.i shape.i shm.i xcmisc.i \
|
||||
xevie.i xf86dri.i xf86vidmode.i xfixes.i xinerama.i \
|
||||
xprint.i xproto.i xselinux.i xtest.i xv.i xvmc.i
|
||||
go install
|
||||
|
||||
%.i:
|
||||
(cd $* ; go install)
|
||||
|
||||
# xc_misc is special because it has an underscore.
|
||||
# There's probably a way to do this better, but Makefiles aren't my strong suit.
|
||||
xc_misc.xml: build-xgbgen
|
||||
mkdir -p xcmisc
|
||||
xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/xc_misc.xml > xcmisc/xcmisc.go
|
||||
|
||||
%.xml: build-xgbgen
|
||||
mkdir -p $*
|
||||
xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/$*.xml > $*/$*.go
|
||||
|
||||
# Just test the xproto core protocol for now.
|
||||
test:
|
||||
(cd xproto ; go test)
|
||||
|
||||
# Force all xproto benchmarks to run and no tests.
|
||||
bench:
|
||||
(cd xproto ; go test -run 'nomatch' -bench '.*' -cpu 1,2,3,6)
|
||||
|
||||
# gofmt all non-auto-generated code.
|
||||
# (auto-generated code is already gofmt'd.)
|
||||
# Also do a column check (80 cols) after a gofmt.
|
||||
# But don't check columns on auto-generated code, since I don't care if they
|
||||
# break 80 cols.
|
||||
gofmt:
|
||||
gofmt -w *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go
|
||||
colcheck *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go
|
||||
|
||||
push:
|
||||
git push origin master
|
||||
git push github master
|
||||
|
54
vendor/github.com/BurntSushi/xgb/README
generated
vendored
54
vendor/github.com/BurntSushi/xgb/README
generated
vendored
@ -1,54 +0,0 @@
|
||||
XGB is the X Go Binding, which is a low-level API to communicate with the
|
||||
core X protocol and many of the X extensions. It is closely modeled after
|
||||
XCB and xpyb.
|
||||
|
||||
It is thread safe and gets immediate improvement from parallelism when
|
||||
GOMAXPROCS > 1. (See the benchmarks in xproto/xproto_test.go for evidence.)
|
||||
|
||||
Please see doc.go for more info.
|
||||
|
||||
Note that unless you know you need XGB, you can probably make your life
|
||||
easier by using a slightly higher level library: xgbutil.
|
||||
|
||||
Quick Usage
|
||||
===========
|
||||
go get github.com/BurntSushi/xgb
|
||||
go run go/path/src/github.com/BurntSushi/xgb/examples/create-window/main.go
|
||||
|
||||
BurntSushi's Fork
|
||||
=================
|
||||
I've forked the XGB repository from Google Code due to inactivty upstream.
|
||||
|
||||
Godoc documentation can be found here:
|
||||
http://godoc.burntsushi.net/pkg/github.com/BurntSushi/xgb/
|
||||
|
||||
Much of the code has been rewritten in an effort to support thread safety
|
||||
and multiple extensions. Namely, go_client.py has been thrown away in favor
|
||||
of an xgbgen package.
|
||||
|
||||
The biggest parts that *haven't* been rewritten by me are the connection and
|
||||
authentication handshakes. They're inherently messy, and there's really no
|
||||
reason to re-work them. The rest of XGB has been completely rewritten.
|
||||
|
||||
I like to release my code under the WTFPL, but since I'm starting with someone
|
||||
else's work, I'm leaving the original license/contributor/author information
|
||||
in tact.
|
||||
|
||||
I suppose I can legitimately release xgbgen under the WTFPL. To be fair, it is
|
||||
at least as complex as XGB itself. *sigh*
|
||||
|
||||
What follows is the original README:
|
||||
|
||||
XGB README
|
||||
==========
|
||||
XGB is the X protocol Go language Binding.
|
||||
|
||||
It is the Go equivalent of XCB, the X protocol C-language Binding
|
||||
(http://xcb.freedesktop.org/).
|
||||
|
||||
Unless otherwise noted, the XGB source files are distributed
|
||||
under the BSD-style license found in the LICENSE file.
|
||||
|
||||
Contributions should follow the same procedure as for the Go project:
|
||||
http://golang.org/doc/contribute.html
|
||||
|
29
vendor/github.com/BurntSushi/xgb/STYLE
generated
vendored
29
vendor/github.com/BurntSushi/xgb/STYLE
generated
vendored
@ -1,29 +0,0 @@
|
||||
I like to keep all my code to 80 columns or less. I have plenty of screen real
|
||||
estate, but enjoy 80 columns so that I can have multiple code windows open side
|
||||
to side and not be plagued by the ugly auto-wrapping of a text editor.
|
||||
|
||||
If you don't oblige me, I will fix any patch you submit to abide 80 columns.
|
||||
|
||||
Note that this style restriction does not preclude gofmt, but introduces a few
|
||||
peculiarities. The first is that gofmt will occasionally add spacing (typically
|
||||
to comments) that ends up going over 80 columns. Either shorten the comment or
|
||||
put it on its own line.
|
||||
|
||||
The second and more common hiccup is when a function definition extends beyond
|
||||
80 columns. If one adds line breaks to keep it below 80 columns, gofmt will
|
||||
indent all subsequent lines in a function definition to the same indentation
|
||||
level of the function body. This results in a less-than-ideal separation
|
||||
between function definition and function body. To remedy this, simply add a
|
||||
line break like so:
|
||||
|
||||
func RestackWindowExtra(xu *xgbutil.XUtil, win xproto.Window, stackMode int,
|
||||
sibling xproto.Window, source int) error {
|
||||
|
||||
return ClientEvent(xu, win, "_NET_RESTACK_WINDOW", source, int(sibling),
|
||||
stackMode)
|
||||
}
|
||||
|
||||
Something similar should also be applied to long 'if' or 'for' conditionals,
|
||||
although it would probably be preferrable to break up the conditional to
|
||||
smaller chunks with a few helper variables.
|
||||
|
110
vendor/github.com/BurntSushi/xgb/auth.go
generated
vendored
110
vendor/github.com/BurntSushi/xgb/auth.go
generated
vendored
@ -1,110 +0,0 @@
|
||||
package xgb
|
||||
|
||||
/*
|
||||
auth.go contains functions to facilitate the parsing of .Xauthority files.
|
||||
|
||||
It is largely unmodified from the original XGB package that I forked.
|
||||
*/
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// readAuthority reads the X authority file for the DISPLAY.
|
||||
// If hostname == "" or hostname == "localhost",
|
||||
// then use the system's hostname (as returned by os.Hostname) instead.
|
||||
func readAuthority(hostname, display string) (
|
||||
name string, data []byte, err error) {
|
||||
|
||||
// b is a scratch buffer to use and should be at least 256 bytes long
|
||||
// (i.e. it should be able to hold a hostname).
|
||||
b := make([]byte, 256)
|
||||
|
||||
// As per /usr/include/X11/Xauth.h.
|
||||
const familyLocal = 256
|
||||
const familyWild = 65535
|
||||
|
||||
if len(hostname) == 0 || hostname == "localhost" {
|
||||
hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
}
|
||||
|
||||
fname := os.Getenv("XAUTHORITY")
|
||||
if len(fname) == 0 {
|
||||
home := os.Getenv("HOME")
|
||||
if len(home) == 0 {
|
||||
err = errors.New("Xauthority not found: $XAUTHORITY, $HOME not set")
|
||||
return "", nil, err
|
||||
}
|
||||
fname = home + "/.Xauthority"
|
||||
}
|
||||
|
||||
r, err := os.Open(fname)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
for {
|
||||
var family uint16
|
||||
if err := binary.Read(r, binary.BigEndian, &family); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
addr, err := getString(r, b)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
disp, err := getString(r, b)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
name0, err := getString(r, b)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
data0, err := getBytes(r, b)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
addrmatch := (family == familyWild) ||
|
||||
(family == familyLocal && addr == hostname)
|
||||
dispmatch := (disp == "") || (disp == display)
|
||||
|
||||
if addrmatch && dispmatch {
|
||||
return name0, data0, nil
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func getBytes(r io.Reader, b []byte) ([]byte, error) {
|
||||
var n uint16
|
||||
if err := binary.Read(r, binary.BigEndian, &n); err != nil {
|
||||
return nil, err
|
||||
} else if n > uint16(len(b)) {
|
||||
return nil, errors.New("bytes too long for buffer")
|
||||
}
|
||||
|
||||
if _, err := io.ReadFull(r, b[0:n]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[0:n], nil
|
||||
}
|
||||
|
||||
func getString(r io.Reader, b []byte) (string, error) {
|
||||
b, err := getBytes(r, b)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
185
vendor/github.com/BurntSushi/xgb/conn.go
generated
vendored
185
vendor/github.com/BurntSushi/xgb/conn.go
generated
vendored
@ -1,185 +0,0 @@
|
||||
package xgb
|
||||
|
||||
/*
|
||||
conn.go contains a couple of functions that do some real dirty work related
|
||||
to the initial connection handshake with X.
|
||||
|
||||
This code is largely unmodified from the original XGB package that I forked.
|
||||
*/
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// connect connects to the X server given in the 'display' string,
|
||||
// and does all the necessary setup handshaking.
|
||||
// If 'display' is empty it will be taken from os.Getenv("DISPLAY").
|
||||
// Note that you should read and understand the "Connection Setup" of the
|
||||
// X Protocol Reference Manual before changing this function:
|
||||
// http://goo.gl/4zGQg
|
||||
func (c *Conn) connect(display string) error {
|
||||
err := c.dial(display)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.postConnect()
|
||||
}
|
||||
|
||||
// connect init from to the net.Conn,
|
||||
func (c *Conn) connectNet(netConn net.Conn) error {
|
||||
c.conn = netConn
|
||||
return c.postConnect()
|
||||
}
|
||||
|
||||
// do the postConnect action after Conn get it's underly net.Conn
|
||||
func (c *Conn) postConnect() error {
|
||||
// Get authentication data
|
||||
authName, authData, err := readAuthority(c.host, c.display)
|
||||
noauth := false
|
||||
if err != nil {
|
||||
Logger.Printf("Could not get authority info: %v", err)
|
||||
Logger.Println("Trying connection without authority info...")
|
||||
authName = ""
|
||||
authData = []byte{}
|
||||
noauth = true
|
||||
}
|
||||
|
||||
// Assume that the authentication protocol is "MIT-MAGIC-COOKIE-1".
|
||||
if !noauth && (authName != "MIT-MAGIC-COOKIE-1" || len(authData) != 16) {
|
||||
return errors.New("unsupported auth protocol " + authName)
|
||||
}
|
||||
|
||||
buf := make([]byte, 12+Pad(len(authName))+Pad(len(authData)))
|
||||
buf[0] = 0x6c
|
||||
buf[1] = 0
|
||||
Put16(buf[2:], 11)
|
||||
Put16(buf[4:], 0)
|
||||
Put16(buf[6:], uint16(len(authName)))
|
||||
Put16(buf[8:], uint16(len(authData)))
|
||||
Put16(buf[10:], 0)
|
||||
copy(buf[12:], []byte(authName))
|
||||
copy(buf[12+Pad(len(authName)):], authData)
|
||||
if _, err = c.conn.Write(buf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
head := make([]byte, 8)
|
||||
if _, err = io.ReadFull(c.conn, head[0:8]); err != nil {
|
||||
return err
|
||||
}
|
||||
code := head[0]
|
||||
reasonLen := head[1]
|
||||
major := Get16(head[2:])
|
||||
minor := Get16(head[4:])
|
||||
dataLen := Get16(head[6:])
|
||||
|
||||
if major != 11 || minor != 0 {
|
||||
return fmt.Errorf("x protocol version mismatch: %d.%d", major, minor)
|
||||
}
|
||||
|
||||
buf = make([]byte, int(dataLen)*4+8, int(dataLen)*4+8)
|
||||
copy(buf, head)
|
||||
if _, err = io.ReadFull(c.conn, buf[8:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if code == 0 {
|
||||
reason := buf[8 : 8+reasonLen]
|
||||
return fmt.Errorf("x protocol authentication refused: %s",
|
||||
string(reason))
|
||||
}
|
||||
|
||||
// Unfortunately, it isn't really feasible to read the setup bytes here,
|
||||
// since the code to do so is in a different package.
|
||||
// Users must call 'xproto.Setup(X)' to get the setup info.
|
||||
c.SetupBytes = buf
|
||||
|
||||
// But also read stuff that we *need* to get started.
|
||||
c.setupResourceIdBase = Get32(buf[12:])
|
||||
c.setupResourceIdMask = Get32(buf[16:])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// dial initializes the actual net connection with X.
|
||||
func (c *Conn) dial(display string) error {
|
||||
if len(display) == 0 {
|
||||
display = os.Getenv("DISPLAY")
|
||||
}
|
||||
|
||||
display0 := display
|
||||
if len(display) == 0 {
|
||||
return errors.New("empty display string")
|
||||
}
|
||||
|
||||
colonIdx := strings.LastIndex(display, ":")
|
||||
if colonIdx < 0 {
|
||||
return errors.New("bad display string: " + display0)
|
||||
}
|
||||
|
||||
var protocol, socket string
|
||||
|
||||
if display[0] == '/' {
|
||||
socket = display[0:colonIdx]
|
||||
} else {
|
||||
slashIdx := strings.LastIndex(display, "/")
|
||||
if slashIdx >= 0 {
|
||||
protocol = display[0:slashIdx]
|
||||
c.host = display[slashIdx+1 : colonIdx]
|
||||
} else {
|
||||
c.host = display[0:colonIdx]
|
||||
}
|
||||
}
|
||||
|
||||
display = display[colonIdx+1 : len(display)]
|
||||
if len(display) == 0 {
|
||||
return errors.New("bad display string: " + display0)
|
||||
}
|
||||
|
||||
var scr string
|
||||
dotIdx := strings.LastIndex(display, ".")
|
||||
if dotIdx < 0 {
|
||||
c.display = display[0:]
|
||||
} else {
|
||||
c.display = display[0:dotIdx]
|
||||
scr = display[dotIdx+1:]
|
||||
}
|
||||
|
||||
var err error
|
||||
c.DisplayNumber, err = strconv.Atoi(c.display)
|
||||
if err != nil || c.DisplayNumber < 0 {
|
||||
return errors.New("bad display string: " + display0)
|
||||
}
|
||||
|
||||
if len(scr) != 0 {
|
||||
c.DefaultScreen, err = strconv.Atoi(scr)
|
||||
if err != nil {
|
||||
return errors.New("bad display string: " + display0)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to server
|
||||
if len(socket) != 0 {
|
||||
c.conn, err = net.Dial("unix", socket+":"+c.display)
|
||||
} else if len(c.host) != 0 {
|
||||
if protocol == "" {
|
||||
protocol = "tcp"
|
||||
}
|
||||
c.conn, err = net.Dial(protocol,
|
||||
c.host+":"+strconv.Itoa(6000+c.DisplayNumber))
|
||||
} else {
|
||||
c.conn, err = net.Dial("unix", "/tmp/.X11-unix/X"+c.display)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.New("cannot connect to " + display0 + ": " + err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
165
vendor/github.com/BurntSushi/xgb/cookie.go
generated
vendored
165
vendor/github.com/BurntSushi/xgb/cookie.go
generated
vendored
@ -1,165 +0,0 @@
|
||||
package xgb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Cookie is the internal representation of a cookie, where one is generated
|
||||
// for *every* request sent by XGB.
|
||||
// 'cookie' is most frequently used by embedding it into a more specific
|
||||
// kind of cookie, i.e., 'GetInputFocusCookie'.
|
||||
type Cookie struct {
|
||||
conn *Conn
|
||||
Sequence uint16
|
||||
replyChan chan []byte
|
||||
errorChan chan error
|
||||
pingChan chan bool
|
||||
}
|
||||
|
||||
// NewCookie creates a new cookie with the correct channels initialized
|
||||
// depending upon the values of 'checked' and 'reply'. Together, there are
|
||||
// four different kinds of cookies. (See more detailed comments in the
|
||||
// function for more info on those.)
|
||||
// Note that a sequence number is not set until just before the request
|
||||
// corresponding to this cookie is sent over the wire.
|
||||
//
|
||||
// Unless you're building requests from bytes by hand, this method should
|
||||
// not be used.
|
||||
func (c *Conn) NewCookie(checked, reply bool) *Cookie {
|
||||
cookie := &Cookie{
|
||||
conn: c,
|
||||
Sequence: 0, // we add the sequence id just before sending a request
|
||||
replyChan: nil,
|
||||
errorChan: nil,
|
||||
pingChan: nil,
|
||||
}
|
||||
|
||||
// There are four different kinds of cookies:
|
||||
// Checked requests with replies get a reply channel and an error channel.
|
||||
// Unchecked requests with replies get a reply channel and a ping channel.
|
||||
// Checked requests w/o replies get a ping channel and an error channel.
|
||||
// Unchecked requests w/o replies get no channels.
|
||||
// The reply channel is used to send reply data.
|
||||
// The error channel is used to send error data.
|
||||
// The ping channel is used when one of the 'reply' or 'error' channels
|
||||
// is missing but the other is present. The ping channel is way to force
|
||||
// the blocking to stop and basically say "the error has been received
|
||||
// in the main event loop" (when the ping channel is coupled with a reply
|
||||
// channel) or "the request you made that has no reply was successful"
|
||||
// (when the ping channel is coupled with an error channel).
|
||||
if checked {
|
||||
cookie.errorChan = make(chan error, 1)
|
||||
if !reply {
|
||||
cookie.pingChan = make(chan bool, 1)
|
||||
}
|
||||
}
|
||||
if reply {
|
||||
cookie.replyChan = make(chan []byte, 1)
|
||||
if !checked {
|
||||
cookie.pingChan = make(chan bool, 1)
|
||||
}
|
||||
}
|
||||
|
||||
return cookie
|
||||
}
|
||||
|
||||
// Reply detects whether this is a checked or unchecked cookie, and calls
|
||||
// 'replyChecked' or 'replyUnchecked' appropriately.
|
||||
//
|
||||
// Unless you're building requests from bytes by hand, this method should
|
||||
// not be used.
|
||||
func (c Cookie) Reply() ([]byte, error) {
|
||||
// checked
|
||||
if c.errorChan != nil {
|
||||
return c.replyChecked()
|
||||
}
|
||||
return c.replyUnchecked()
|
||||
}
|
||||
|
||||
// replyChecked waits for a response on either the replyChan or errorChan
|
||||
// channels. If the former arrives, the bytes are returned with a nil error.
|
||||
// If the latter arrives, no bytes are returned (nil) and the error received
|
||||
// is returned.
|
||||
//
|
||||
// Unless you're building requests from bytes by hand, this method should
|
||||
// not be used.
|
||||
func (c Cookie) replyChecked() ([]byte, error) {
|
||||
if c.replyChan == nil {
|
||||
return nil, errors.New("Cannot call 'replyChecked' on a cookie that " +
|
||||
"is not expecting a *reply* or an error.")
|
||||
}
|
||||
if c.errorChan == nil {
|
||||
return nil, errors.New("Cannot call 'replyChecked' on a cookie that " +
|
||||
"is not expecting a reply or an *error*.")
|
||||
}
|
||||
|
||||
select {
|
||||
case reply := <-c.replyChan:
|
||||
return reply, nil
|
||||
case err := <-c.errorChan:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// replyUnchecked waits for a response on either the replyChan or pingChan
|
||||
// channels. If the former arrives, the bytes are returned with a nil error.
|
||||
// If the latter arrives, no bytes are returned (nil) and a nil error
|
||||
// is returned. (In the latter case, the corresponding error can be retrieved
|
||||
// from (Wait|Poll)ForEvent asynchronously.)
|
||||
// In all honesty, you *probably* don't want to use this method.
|
||||
//
|
||||
// Unless you're building requests from bytes by hand, this method should
|
||||
// not be used.
|
||||
func (c Cookie) replyUnchecked() ([]byte, error) {
|
||||
if c.replyChan == nil {
|
||||
return nil, errors.New("Cannot call 'replyUnchecked' on a cookie " +
|
||||
"that is not expecting a *reply*.")
|
||||
}
|
||||
|
||||
select {
|
||||
case reply := <-c.replyChan:
|
||||
return reply, nil
|
||||
case <-c.pingChan:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check is used for checked requests that have no replies. It is a mechanism
|
||||
// by which to report "success" or "error" in a synchronous fashion. (Therefore,
|
||||
// unchecked requests without replies cannot use this method.)
|
||||
// If the request causes an error, it is sent to this cookie's errorChan.
|
||||
// If the request was successful, there is no response from the server.
|
||||
// Thus, pingChan is sent a value when the *next* reply is read.
|
||||
// If no more replies are being processed, we force a round trip request with
|
||||
// GetInputFocus.
|
||||
//
|
||||
// Unless you're building requests from bytes by hand, this method should
|
||||
// not be used.
|
||||
func (c Cookie) Check() error {
|
||||
if c.replyChan != nil {
|
||||
return errors.New("Cannot call 'Check' on a cookie that is " +
|
||||
"expecting a *reply*. Use 'Reply' instead.")
|
||||
}
|
||||
if c.errorChan == nil {
|
||||
return errors.New("Cannot call 'Check' on a cookie that is " +
|
||||
"not expecting a possible *error*.")
|
||||
}
|
||||
|
||||
// First do a quick non-blocking check to see if we've been pinged.
|
||||
select {
|
||||
case err := <-c.errorChan:
|
||||
return err
|
||||
case <-c.pingChan:
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
|
||||
// Now force a round trip and try again, but block this time.
|
||||
c.conn.Sync()
|
||||
select {
|
||||
case err := <-c.errorChan:
|
||||
return err
|
||||
case <-c.pingChan:
|
||||
return nil
|
||||
}
|
||||
}
|
146
vendor/github.com/BurntSushi/xgb/doc.go
generated
vendored
146
vendor/github.com/BurntSushi/xgb/doc.go
generated
vendored
@ -1,146 +0,0 @@
|
||||
/*
|
||||
Package XGB provides the X Go Binding, which is a low-level API to communicate
|
||||
with the core X protocol and many of the X extensions.
|
||||
|
||||
It is *very* closely modeled on XCB, so that experience with XCB (or xpyb) is
|
||||
easily translatable to XGB. That is, it uses the same cookie/reply model
|
||||
and is thread safe. There are otherwise no major differences (in the API).
|
||||
|
||||
Most uses of XGB typically fall under the realm of window manager and GUI kit
|
||||
development, but other applications (like pagers, panels, tilers, etc.) may
|
||||
also require XGB. Moreover, it is a near certainty that if you need to work
|
||||
with X, xgbutil will be of great use to you as well:
|
||||
https://github.com/BurntSushi/xgbutil
|
||||
|
||||
Example
|
||||
|
||||
This is an extremely terse example that demonstrates how to connect to X,
|
||||
create a window, listen to StructureNotify events and Key{Press,Release}
|
||||
events, map the window, and print out all events received. An example with
|
||||
accompanying documentation can be found in examples/create-window.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
func main() {
|
||||
X, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
wid, _ := xproto.NewWindowId(X)
|
||||
screen := xproto.Setup(X).DefaultScreen(X)
|
||||
xproto.CreateWindow(X, screen.RootDepth, wid, screen.Root,
|
||||
0, 0, 500, 500, 0,
|
||||
xproto.WindowClassInputOutput, screen.RootVisual,
|
||||
xproto.CwBackPixel | xproto.CwEventMask,
|
||||
[]uint32{ // values must be in the order defined by the protocol
|
||||
0xffffffff,
|
||||
xproto.EventMaskStructureNotify |
|
||||
xproto.EventMaskKeyPress |
|
||||
xproto.EventMaskKeyRelease})
|
||||
|
||||
xproto.MapWindow(X, wid)
|
||||
for {
|
||||
ev, xerr := X.WaitForEvent()
|
||||
if ev == nil && xerr == nil {
|
||||
fmt.Println("Both event and error are nil. Exiting...")
|
||||
return
|
||||
}
|
||||
|
||||
if ev != nil {
|
||||
fmt.Printf("Event: %s\n", ev)
|
||||
}
|
||||
if xerr != nil {
|
||||
fmt.Printf("Error: %s\n", xerr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Xinerama Example
|
||||
|
||||
This is another small example that shows how to query Xinerama for geometry
|
||||
information of each active head. Accompanying documentation for this example
|
||||
can be found in examples/xinerama.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xinerama"
|
||||
)
|
||||
|
||||
func main() {
|
||||
X, err := xgb.NewConn()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Initialize the Xinerama extension.
|
||||
// The appropriate 'Init' function must be run for *every*
|
||||
// extension before any of its requests can be used.
|
||||
err = xinerama.Init(X)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
reply, err := xinerama.QueryScreens(X).Reply()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Number of heads: %d\n", reply.Number)
|
||||
for i, screen := range reply.ScreenInfo {
|
||||
fmt.Printf("%d :: X: %d, Y: %d, Width: %d, Height: %d\n",
|
||||
i, screen.XOrg, screen.YOrg, screen.Width, screen.Height)
|
||||
}
|
||||
}
|
||||
|
||||
Parallelism
|
||||
|
||||
XGB can benefit greatly from parallelism due to its concurrent design. For
|
||||
evidence of this claim, please see the benchmarks in xproto/xproto_test.go.
|
||||
|
||||
Tests
|
||||
|
||||
xproto/xproto_test.go contains a number of contrived tests that stress
|
||||
particular corners of XGB that I presume could be problem areas. Namely:
|
||||
requests with no replies, requests with replies, checked errors, unchecked
|
||||
errors, sequence number wrapping, cookie buffer flushing (i.e., forcing a round
|
||||
trip every N requests made that don't have a reply), getting/setting properties
|
||||
and creating a window and listening to StructureNotify events.
|
||||
|
||||
Code Generator
|
||||
|
||||
Both XCB and xpyb use the same Python module (xcbgen) for a code generator. XGB
|
||||
(before this fork) used the same code generator as well, but in my attempt to
|
||||
add support for more extensions, I found the code generator extremely difficult
|
||||
to work with. Therefore, I re-wrote the code generator in Go. It can be found
|
||||
in its own sub-package, xgbgen, of xgb. My design of xgbgen includes a rough
|
||||
consideration that it could be used for other languages.
|
||||
|
||||
What works
|
||||
|
||||
I am reasonably confident that the core X protocol is in full working form. I've
|
||||
also tested the Xinerama and RandR extensions sparingly. Many of the other
|
||||
existing extensions have Go source generated (and are compilable) and are
|
||||
included in this package, but I am currently unsure of their status. They
|
||||
*should* work.
|
||||
|
||||
What does not work
|
||||
|
||||
XKB is the only extension that intentionally does not work, although I suspect
|
||||
that GLX also does not work (however, there is Go source code for GLX that
|
||||
compiles, unlike XKB). I don't currently have any intention of getting XKB
|
||||
working, due to its complexity and my current mental incapacity to test it.
|
||||
|
||||
*/
|
||||
package xgb
|
105
vendor/github.com/BurntSushi/xgb/help.go
generated
vendored
105
vendor/github.com/BurntSushi/xgb/help.go
generated
vendored
@ -1,105 +0,0 @@
|
||||
package xgb
|
||||
|
||||
/*
|
||||
help.go is meant to contain a rough hodge podge of functions that are mainly
|
||||
used in the auto generated code. Indeed, several functions here are simple
|
||||
wrappers so that the sub-packages don't need to be smart about which stdlib
|
||||
packages to import.
|
||||
|
||||
Also, the 'Get..' and 'Put..' functions are used through the core xgb package
|
||||
too. (xgbutil uses them too.)
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// StringsJoin is an alias to strings.Join. It allows us to avoid having to
|
||||
// import 'strings' in each of the generated Go files.
|
||||
func StringsJoin(ss []string, sep string) string {
|
||||
return strings.Join(ss, sep)
|
||||
}
|
||||
|
||||
// Sprintf is so we don't need to import 'fmt' in the generated Go files.
|
||||
func Sprintf(format string, v ...interface{}) string {
|
||||
return fmt.Sprintf(format, v...)
|
||||
}
|
||||
|
||||
// Errorf is just a wrapper for fmt.Errorf. Exists for the same reason
|
||||
// that 'stringsJoin' and 'sprintf' exists.
|
||||
func Errorf(format string, v ...interface{}) error {
|
||||
return fmt.Errorf(format, v...)
|
||||
}
|
||||
|
||||
// Pad a length to align on 4 bytes.
|
||||
func Pad(n int) int {
|
||||
return (n + 3) & ^3
|
||||
}
|
||||
|
||||
// PopCount counts the number of bits set in a value list mask.
|
||||
func PopCount(mask0 int) int {
|
||||
mask := uint32(mask0)
|
||||
n := 0
|
||||
for i := uint32(0); i < 32; i++ {
|
||||
if mask&(1<<i) != 0 {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Put16 takes a 16 bit integer and copies it into a byte slice.
|
||||
func Put16(buf []byte, v uint16) {
|
||||
buf[0] = byte(v)
|
||||
buf[1] = byte(v >> 8)
|
||||
}
|
||||
|
||||
// Put32 takes a 32 bit integer and copies it into a byte slice.
|
||||
func Put32(buf []byte, v uint32) {
|
||||
buf[0] = byte(v)
|
||||
buf[1] = byte(v >> 8)
|
||||
buf[2] = byte(v >> 16)
|
||||
buf[3] = byte(v >> 24)
|
||||
}
|
||||
|
||||
// Put64 takes a 64 bit integer and copies it into a byte slice.
|
||||
func Put64(buf []byte, v uint64) {
|
||||
buf[0] = byte(v)
|
||||
buf[1] = byte(v >> 8)
|
||||
buf[2] = byte(v >> 16)
|
||||
buf[3] = byte(v >> 24)
|
||||
buf[4] = byte(v >> 32)
|
||||
buf[5] = byte(v >> 40)
|
||||
buf[6] = byte(v >> 48)
|
||||
buf[7] = byte(v >> 56)
|
||||
}
|
||||
|
||||
// Get16 constructs a 16 bit integer from the beginning of a byte slice.
|
||||
func Get16(buf []byte) uint16 {
|
||||
v := uint16(buf[0])
|
||||
v |= uint16(buf[1]) << 8
|
||||
return v
|
||||
}
|
||||
|
||||
// Get32 constructs a 32 bit integer from the beginning of a byte slice.
|
||||
func Get32(buf []byte) uint32 {
|
||||
v := uint32(buf[0])
|
||||
v |= uint32(buf[1]) << 8
|
||||
v |= uint32(buf[2]) << 16
|
||||
v |= uint32(buf[3]) << 24
|
||||
return v
|
||||
}
|
||||
|
||||
// Get64 constructs a 64 bit integer from the beginning of a byte slice.
|
||||
func Get64(buf []byte) uint64 {
|
||||
v := uint64(buf[0])
|
||||
v |= uint64(buf[1]) << 8
|
||||
v |= uint64(buf[2]) << 16
|
||||
v |= uint64(buf[3]) << 24
|
||||
v |= uint64(buf[4]) << 32
|
||||
v |= uint64(buf[5]) << 40
|
||||
v |= uint64(buf[6]) << 48
|
||||
v |= uint64(buf[7]) << 56
|
||||
return v
|
||||
}
|
1025
vendor/github.com/BurntSushi/xgb/shape/shape.go
generated
vendored
1025
vendor/github.com/BurntSushi/xgb/shape/shape.go
generated
vendored
File diff suppressed because it is too large
Load Diff
29
vendor/github.com/BurntSushi/xgb/sync.go
generated
vendored
29
vendor/github.com/BurntSushi/xgb/sync.go
generated
vendored
@ -1,29 +0,0 @@
|
||||
package xgb
|
||||
|
||||
// Sync sends a round trip request and waits for the response.
|
||||
// This forces all pending cookies to be dealt with.
|
||||
// You actually shouldn't need to use this like you might with Xlib. Namely,
|
||||
// buffers are automatically flushed using Go's channels and round trip requests
|
||||
// are forced where appropriate automatically.
|
||||
func (c *Conn) Sync() {
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(c.getInputFocusRequest(), cookie)
|
||||
cookie.Reply() // wait for the buffer to clear
|
||||
}
|
||||
|
||||
// getInputFocusRequest writes the raw bytes to a buffer.
|
||||
// It is duplicated from xproto/xproto.go.
|
||||
func (c *Conn) getInputFocusRequest() []byte {
|
||||
size := 4
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
buf[b] = 43 // request opcode
|
||||
b += 1
|
||||
|
||||
b += 1 // padding
|
||||
Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
return buf
|
||||
}
|
554
vendor/github.com/BurntSushi/xgb/xgb.go
generated
vendored
554
vendor/github.com/BurntSushi/xgb/xgb.go
generated
vendored
@ -1,554 +0,0 @@
|
||||
package xgb
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// Where to log error-messages. Defaults to stderr.
|
||||
// To disable logging, just set this to log.New(ioutil.Discard, "", 0)
|
||||
Logger = log.New(os.Stderr, "XGB: ", log.Lshortfile)
|
||||
)
|
||||
|
||||
const (
|
||||
// cookieBuffer represents the queue size of cookies existing at any
|
||||
// point in time. The size of the buffer is really only important when
|
||||
// there are many requests without replies made in sequence. Once the
|
||||
// buffer fills, a round trip request is made to clear the buffer.
|
||||
cookieBuffer = 1000
|
||||
|
||||
// xidBuffer represents the queue size of the xid channel.
|
||||
// I don't think this value matters much, since xid generation is not
|
||||
// that expensive.
|
||||
xidBuffer = 5
|
||||
|
||||
// seqBuffer represents the queue size of the sequence number channel.
|
||||
// I don't think this value matters much, since sequence number generation
|
||||
// is not that expensive.
|
||||
seqBuffer = 5
|
||||
|
||||
// reqBuffer represents the queue size of the number of requests that
|
||||
// can be made until new ones block. This value seems OK.
|
||||
reqBuffer = 100
|
||||
|
||||
// eventBuffer represents the queue size of the number of events or errors
|
||||
// that can be loaded off the wire and not grabbed with WaitForEvent
|
||||
// until reading an event blocks. This value should be big enough to handle
|
||||
// bursts of events.
|
||||
eventBuffer = 5000
|
||||
)
|
||||
|
||||
// A Conn represents a connection to an X server.
|
||||
type Conn struct {
|
||||
host string
|
||||
conn net.Conn
|
||||
display string
|
||||
DisplayNumber int
|
||||
DefaultScreen int
|
||||
SetupBytes []byte
|
||||
|
||||
setupResourceIdBase uint32
|
||||
setupResourceIdMask uint32
|
||||
|
||||
eventChan chan eventOrError
|
||||
cookieChan chan *Cookie
|
||||
xidChan chan xid
|
||||
seqChan chan uint16
|
||||
reqChan chan *request
|
||||
closing chan chan struct{}
|
||||
|
||||
// ExtLock is a lock used whenever new extensions are initialized.
|
||||
// It should not be used. It is exported for use in the extension
|
||||
// sub-packages.
|
||||
ExtLock sync.RWMutex
|
||||
|
||||
// Extensions is a map from extension name to major opcode. It should
|
||||
// not be used. It is exported for use in the extension sub-packages.
|
||||
Extensions map[string]byte
|
||||
}
|
||||
|
||||
// NewConn creates a new connection instance. It initializes locks, data
|
||||
// structures, and performs the initial handshake. (The code for the handshake
|
||||
// has been relegated to conn.go.)
|
||||
func NewConn() (*Conn, error) {
|
||||
return NewConnDisplay("")
|
||||
}
|
||||
|
||||
// NewConnDisplay is just like NewConn, but allows a specific DISPLAY
|
||||
// string to be used.
|
||||
// If 'display' is empty it will be taken from os.Getenv("DISPLAY").
|
||||
//
|
||||
// Examples:
|
||||
// NewConn(":1") -> net.Dial("unix", "", "/tmp/.X11-unix/X1")
|
||||
// NewConn("/tmp/launch-12/:0") -> net.Dial("unix", "", "/tmp/launch-12/:0")
|
||||
// NewConn("hostname:2.1") -> net.Dial("tcp", "", "hostname:6002")
|
||||
// NewConn("tcp/hostname:1.0") -> net.Dial("tcp", "", "hostname:6001")
|
||||
func NewConnDisplay(display string) (*Conn, error) {
|
||||
conn := &Conn{}
|
||||
|
||||
// First connect. This reads authority, checks DISPLAY environment
|
||||
// variable, and loads the initial Setup info.
|
||||
err := conn.connect(display)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return postNewConn(conn)
|
||||
}
|
||||
|
||||
// NewConnDisplay is just like NewConn, but allows a specific net.Conn
|
||||
// to be used.
|
||||
func NewConnNet(netConn net.Conn) (*Conn, error) {
|
||||
conn := &Conn{}
|
||||
|
||||
// First connect. This reads authority, checks DISPLAY environment
|
||||
// variable, and loads the initial Setup info.
|
||||
err := conn.connectNet(netConn)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return postNewConn(conn)
|
||||
}
|
||||
|
||||
func postNewConn(conn *Conn) (*Conn, error) {
|
||||
conn.Extensions = make(map[string]byte)
|
||||
|
||||
conn.cookieChan = make(chan *Cookie, cookieBuffer)
|
||||
conn.xidChan = make(chan xid, xidBuffer)
|
||||
conn.seqChan = make(chan uint16, seqBuffer)
|
||||
conn.reqChan = make(chan *request, reqBuffer)
|
||||
conn.eventChan = make(chan eventOrError, eventBuffer)
|
||||
conn.closing = make(chan chan struct{}, 1)
|
||||
|
||||
go conn.generateXIds()
|
||||
go conn.generateSeqIds()
|
||||
go conn.sendRequests()
|
||||
go conn.readResponses()
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// Close gracefully closes the connection to the X server.
|
||||
func (c *Conn) Close() {
|
||||
close(c.reqChan)
|
||||
}
|
||||
|
||||
// Event is an interface that can contain any of the events returned by the
|
||||
// server. Use a type assertion switch to extract the Event structs.
|
||||
type Event interface {
|
||||
Bytes() []byte
|
||||
String() string
|
||||
}
|
||||
|
||||
// NewEventFun is the type of function use to construct events from raw bytes.
|
||||
// It should not be used. It is exported for use in the extension sub-packages.
|
||||
type NewEventFun func(buf []byte) Event
|
||||
|
||||
// NewEventFuncs is a map from event numbers to functions that create
|
||||
// the corresponding event. It should not be used. It is exported for use
|
||||
// in the extension sub-packages.
|
||||
var NewEventFuncs = make(map[int]NewEventFun)
|
||||
|
||||
// NewExtEventFuncs is a temporary map that stores event constructor functions
|
||||
// for each extension. When an extension is initialized, each event for that
|
||||
// extension is added to the 'NewEventFuncs' map. It should not be used. It is
|
||||
// exported for use in the extension sub-packages.
|
||||
var NewExtEventFuncs = make(map[string]map[int]NewEventFun)
|
||||
|
||||
// Error is an interface that can contain any of the errors returned by
|
||||
// the server. Use a type assertion switch to extract the Error structs.
|
||||
type Error interface {
|
||||
SequenceId() uint16
|
||||
BadId() uint32
|
||||
Error() string
|
||||
}
|
||||
|
||||
// NewErrorFun is the type of function use to construct errors from raw bytes.
|
||||
// It should not be used. It is exported for use in the extension sub-packages.
|
||||
type NewErrorFun func(buf []byte) Error
|
||||
|
||||
// NewErrorFuncs is a map from error numbers to functions that create
|
||||
// the corresponding error. It should not be used. It is exported for use in
|
||||
// the extension sub-packages.
|
||||
var NewErrorFuncs = make(map[int]NewErrorFun)
|
||||
|
||||
// NewExtErrorFuncs is a temporary map that stores error constructor functions
|
||||
// for each extension. When an extension is initialized, each error for that
|
||||
// extension is added to the 'NewErrorFuncs' map. It should not be used. It is
|
||||
// exported for use in the extension sub-packages.
|
||||
var NewExtErrorFuncs = make(map[string]map[int]NewErrorFun)
|
||||
|
||||
// eventOrError corresponds to values that can be either an event or an
|
||||
// error.
|
||||
type eventOrError interface{}
|
||||
|
||||
// NewId generates a new unused ID for use with requests like CreateWindow.
|
||||
// If no new ids can be generated, the id returned is 0 and error is non-nil.
|
||||
// This shouldn't be used directly, and is exported for use in the extension
|
||||
// sub-packages.
|
||||
// If you need identifiers, use the appropriate constructor.
|
||||
// e.g., For a window id, use xproto.NewWindowId. For
|
||||
// a new pixmap id, use xproto.NewPixmapId. And so on.
|
||||
func (c *Conn) NewId() (uint32, error) {
|
||||
xid := <-c.xidChan
|
||||
if xid.err != nil {
|
||||
return 0, xid.err
|
||||
}
|
||||
return xid.id, nil
|
||||
}
|
||||
|
||||
// xid encapsulates a resource identifier being sent over the Conn.xidChan
|
||||
// channel. If no new resource id can be generated, id is set to 0 and a
|
||||
// non-nil error is set in xid.err.
|
||||
type xid struct {
|
||||
id uint32
|
||||
err error
|
||||
}
|
||||
|
||||
// generateXids sends new Ids down the channel for NewId to use.
|
||||
// generateXids should be run in its own goroutine.
|
||||
// This needs to be updated to use the XC Misc extension once we run out of
|
||||
// new ids.
|
||||
// Thanks to libxcb/src/xcb_xid.c. This code is greatly inspired by it.
|
||||
func (conn *Conn) generateXIds() {
|
||||
defer close(conn.xidChan)
|
||||
|
||||
// This requires some explanation. From the horse's mouth:
|
||||
// "The resource-id-mask contains a single contiguous set of bits (at least
|
||||
// 18). The client allocates resource IDs for types WINDOW, PIXMAP,
|
||||
// CURSOR, FONT, GCONTEXT, and COLORMAP by choosing a value with only some
|
||||
// subset of these bits set and ORing it with resource-id-base. Only values
|
||||
// constructed in this way can be used to name newly created resources over
|
||||
// this connection."
|
||||
// So for example (using 8 bit integers), the mask might look like:
|
||||
// 00111000
|
||||
// So that valid values would be 00101000, 00110000, 00001000, and so on.
|
||||
// Thus, the idea is to increment it by the place of the last least
|
||||
// significant '1'. In this case, that value would be 00001000. To get
|
||||
// that value, we can AND the original mask with its two's complement:
|
||||
// 00111000 & 11001000 = 00001000.
|
||||
// And we use that value to increment the last resource id to get a new one.
|
||||
// (And then, of course, we OR it with resource-id-base.)
|
||||
inc := conn.setupResourceIdMask & -conn.setupResourceIdMask
|
||||
max := conn.setupResourceIdMask
|
||||
last := uint32(0)
|
||||
for {
|
||||
// TODO: Use the XC Misc extension to look for released ids.
|
||||
if last > 0 && last >= max-inc+1 {
|
||||
conn.xidChan <- xid{
|
||||
id: 0,
|
||||
err: errors.New("There are no more available resource" +
|
||||
"identifiers."),
|
||||
}
|
||||
}
|
||||
|
||||
last += inc
|
||||
conn.xidChan <- xid{
|
||||
id: last | conn.setupResourceIdBase,
|
||||
err: nil,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// newSeqId fetches the next sequence id from the Conn.seqChan channel.
|
||||
func (c *Conn) newSequenceId() uint16 {
|
||||
return <-c.seqChan
|
||||
}
|
||||
|
||||
// generateSeqIds returns new sequence ids. It is meant to be run in its
|
||||
// own goroutine.
|
||||
// A sequence id is generated for *every* request. It's the identifier used
|
||||
// to match up replies with requests.
|
||||
// Since sequence ids can only be 16 bit integers we start over at zero when it
|
||||
// comes time to wrap.
|
||||
// N.B. As long as the cookie buffer is less than 2^16, there are no limitations
|
||||
// on the number (or kind) of requests made in sequence.
|
||||
func (c *Conn) generateSeqIds() {
|
||||
defer close(c.seqChan)
|
||||
|
||||
seqid := uint16(1)
|
||||
for {
|
||||
c.seqChan <- seqid
|
||||
if seqid == uint16((1<<16)-1) {
|
||||
seqid = 0
|
||||
} else {
|
||||
seqid++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// request encapsulates a buffer of raw bytes (containing the request data)
|
||||
// and a cookie, which when combined represents a single request.
|
||||
// The cookie is used to match up the reply/error.
|
||||
type request struct {
|
||||
buf []byte
|
||||
cookie *Cookie
|
||||
|
||||
// seq is closed when the request (cookie) has been sequenced by the Conn.
|
||||
seq chan struct{}
|
||||
}
|
||||
|
||||
// NewRequest takes the bytes and a cookie of a particular request, constructs
|
||||
// a request type, and sends it over the Conn.reqChan channel.
|
||||
// Note that the sequence number is added to the cookie after it is sent
|
||||
// over the request channel, but before it is sent to X.
|
||||
//
|
||||
// Note that you may safely use NewRequest to send arbitrary byte requests
|
||||
// to X. The resulting cookie can be used just like any normal cookie and
|
||||
// abides by the same rules, except that for replies, you'll get back the
|
||||
// raw byte data. This may be useful for performance critical sections where
|
||||
// every allocation counts, since all X requests in XGB allocate a new byte
|
||||
// slice. In contrast, NewRequest allocates one small request struct and
|
||||
// nothing else. (Except when the cookie buffer is full and has to be flushed.)
|
||||
//
|
||||
// If you're using NewRequest manually, you'll need to use NewCookie to create
|
||||
// a new cookie.
|
||||
//
|
||||
// In all likelihood, you should be able to copy and paste with some minor
|
||||
// edits the generated code for the request you want to issue.
|
||||
func (c *Conn) NewRequest(buf []byte, cookie *Cookie) {
|
||||
seq := make(chan struct{})
|
||||
c.reqChan <- &request{buf: buf, cookie: cookie, seq: seq}
|
||||
<-seq
|
||||
}
|
||||
|
||||
// sendRequests is run as a single goroutine that takes requests and writes
|
||||
// the bytes to the wire and adds the cookie to the cookie queue.
|
||||
// It is meant to be run as its own goroutine.
|
||||
func (c *Conn) sendRequests() {
|
||||
defer close(c.cookieChan)
|
||||
|
||||
for req := range c.reqChan {
|
||||
// ho there! if the cookie channel is nearly full, force a round
|
||||
// trip to clear out the cookie buffer.
|
||||
// Note that we circumvent the request channel, because we're *in*
|
||||
// the request channel.
|
||||
if len(c.cookieChan) == cookieBuffer-1 {
|
||||
if err := c.noop(); err != nil {
|
||||
// Shut everything down.
|
||||
break
|
||||
}
|
||||
}
|
||||
req.cookie.Sequence = c.newSequenceId()
|
||||
c.cookieChan <- req.cookie
|
||||
c.writeBuffer(req.buf)
|
||||
close(req.seq)
|
||||
}
|
||||
response := make(chan struct{})
|
||||
c.closing <- response
|
||||
c.noop() // Flush the response reading goroutine, ignore error.
|
||||
<-response
|
||||
c.conn.Close()
|
||||
}
|
||||
|
||||
// noop circumvents the usual request sending goroutines and forces a round
|
||||
// trip request manually.
|
||||
func (c *Conn) noop() error {
|
||||
cookie := c.NewCookie(true, true)
|
||||
cookie.Sequence = c.newSequenceId()
|
||||
c.cookieChan <- cookie
|
||||
if err := c.writeBuffer(c.getInputFocusRequest()); err != nil {
|
||||
return err
|
||||
}
|
||||
cookie.Reply() // wait for the buffer to clear
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeBuffer is a convenience function for writing a byte slice to the wire.
|
||||
func (c *Conn) writeBuffer(buf []byte) error {
|
||||
if _, err := c.conn.Write(buf); err != nil {
|
||||
Logger.Printf("A write error is unrecoverable: %s", err)
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// readResponses is a goroutine that reads events, errors and
|
||||
// replies off the wire.
|
||||
// When an event is read, it is always added to the event channel.
|
||||
// When an error is read, if it corresponds to an existing checked cookie,
|
||||
// it is sent to that cookie's error channel. Otherwise it is added to the
|
||||
// event channel.
|
||||
// When a reply is read, it is added to the corresponding cookie's reply
|
||||
// channel. (It is an error if no such cookie exists in this case.)
|
||||
// Finally, cookies that came "before" this reply are always cleaned up.
|
||||
func (c *Conn) readResponses() {
|
||||
defer close(c.eventChan)
|
||||
|
||||
var (
|
||||
err Error
|
||||
seq uint16
|
||||
replyBytes []byte
|
||||
)
|
||||
|
||||
for {
|
||||
select {
|
||||
case respond := <-c.closing:
|
||||
respond <- struct{}{}
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
buf := make([]byte, 32)
|
||||
err, seq = nil, 0
|
||||
if _, err := io.ReadFull(c.conn, buf); err != nil {
|
||||
Logger.Printf("A read error is unrecoverable: %s", err)
|
||||
c.eventChan <- err
|
||||
c.Close()
|
||||
continue
|
||||
}
|
||||
switch buf[0] {
|
||||
case 0: // This is an error
|
||||
// Use the constructor function for this error (that is auto
|
||||
// generated) by looking it up by the error number.
|
||||
newErrFun, ok := NewErrorFuncs[int(buf[1])]
|
||||
if !ok {
|
||||
Logger.Printf("BUG: Could not find error constructor function "+
|
||||
"for error with number %d.", buf[1])
|
||||
continue
|
||||
}
|
||||
err = newErrFun(buf)
|
||||
seq = err.SequenceId()
|
||||
|
||||
// This error is either sent to the event channel or a specific
|
||||
// cookie's error channel below.
|
||||
case 1: // This is a reply
|
||||
seq = Get16(buf[2:])
|
||||
|
||||
// check to see if this reply has more bytes to be read
|
||||
size := Get32(buf[4:])
|
||||
if size > 0 {
|
||||
byteCount := 32 + size*4
|
||||
biggerBuf := make([]byte, byteCount)
|
||||
copy(biggerBuf[:32], buf)
|
||||
if _, err := io.ReadFull(c.conn, biggerBuf[32:]); err != nil {
|
||||
Logger.Printf("A read error is unrecoverable: %s", err)
|
||||
c.eventChan <- err
|
||||
c.Close()
|
||||
continue
|
||||
}
|
||||
replyBytes = biggerBuf
|
||||
} else {
|
||||
replyBytes = buf
|
||||
}
|
||||
|
||||
// This reply is sent to its corresponding cookie below.
|
||||
default: // This is an event
|
||||
// Use the constructor function for this event (like for errors,
|
||||
// and is also auto generated) by looking it up by the event number.
|
||||
// Note that we AND the event number with 127 so that we ignore
|
||||
// the most significant bit (which is set when it was sent from
|
||||
// a SendEvent request).
|
||||
evNum := int(buf[0] & 127)
|
||||
newEventFun, ok := NewEventFuncs[evNum]
|
||||
if !ok {
|
||||
Logger.Printf("BUG: Could not find event construct function "+
|
||||
"for event with number %d.", evNum)
|
||||
continue
|
||||
}
|
||||
c.eventChan <- newEventFun(buf)
|
||||
continue
|
||||
}
|
||||
|
||||
// At this point, we have a sequence number and we're either
|
||||
// processing an error or a reply, which are both responses to
|
||||
// requests. So all we have to do is find the cookie corresponding
|
||||
// to this error/reply, and send the appropriate data to it.
|
||||
// In doing so, we make sure that any cookies that came before it
|
||||
// are marked as successful if they are void and checked.
|
||||
// If there's a cookie that requires a reply that is before this
|
||||
// reply, then something is wrong.
|
||||
for cookie := range c.cookieChan {
|
||||
// This is the cookie we're looking for. Process and break.
|
||||
if cookie.Sequence == seq {
|
||||
if err != nil { // this is an error to a request
|
||||
// synchronous processing
|
||||
if cookie.errorChan != nil {
|
||||
cookie.errorChan <- err
|
||||
} else { // asynchronous processing
|
||||
c.eventChan <- err
|
||||
// if this is an unchecked reply, ping the cookie too
|
||||
if cookie.pingChan != nil {
|
||||
cookie.pingChan <- true
|
||||
}
|
||||
}
|
||||
} else { // this is a reply
|
||||
if cookie.replyChan == nil {
|
||||
Logger.Printf("Reply with sequence id %d does not "+
|
||||
"have a cookie with a valid reply channel.", seq)
|
||||
continue
|
||||
} else {
|
||||
cookie.replyChan <- replyBytes
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
switch {
|
||||
// Checked requests with replies
|
||||
case cookie.replyChan != nil && cookie.errorChan != nil:
|
||||
Logger.Printf("Found cookie with sequence id %d that is "+
|
||||
"expecting a reply but will never get it. Currently "+
|
||||
"on sequence number %d", cookie.Sequence, seq)
|
||||
// Unchecked requests with replies
|
||||
case cookie.replyChan != nil && cookie.pingChan != nil:
|
||||
Logger.Printf("Found cookie with sequence id %d that is "+
|
||||
"expecting a reply (and not an error) but will never "+
|
||||
"get it. Currently on sequence number %d",
|
||||
cookie.Sequence, seq)
|
||||
// Checked requests without replies
|
||||
case cookie.pingChan != nil && cookie.errorChan != nil:
|
||||
cookie.pingChan <- true
|
||||
// Unchecked requests without replies don't have any channels,
|
||||
// so we can't do anything with them except let them pass by.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// processEventOrError takes an eventOrError, type switches on it,
|
||||
// and returns it in Go idiomatic style.
|
||||
func processEventOrError(everr eventOrError) (Event, Error) {
|
||||
switch ee := everr.(type) {
|
||||
case Event:
|
||||
return ee, nil
|
||||
case Error:
|
||||
return nil, ee
|
||||
default:
|
||||
Logger.Printf("Invalid event/error type: %T", everr)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// WaitForEvent returns the next event from the server.
|
||||
// It will block until an event is available.
|
||||
// WaitForEvent returns either an Event or an Error. (Returning both
|
||||
// is a bug.) Note than an Error here is an X error and not an XGB error. That
|
||||
// is, X errors are sometimes completely expected (and you may want to ignore
|
||||
// them in some cases).
|
||||
//
|
||||
// If both the event and error are nil, then the connection has been closed.
|
||||
func (c *Conn) WaitForEvent() (Event, Error) {
|
||||
return processEventOrError(<-c.eventChan)
|
||||
}
|
||||
|
||||
// PollForEvent returns the next event from the server if one is available in
|
||||
// the internal queue without blocking. Note that unlike WaitForEvent, both
|
||||
// Event and Error could be nil. Indeed, they are both nil when the event queue
|
||||
// is empty.
|
||||
func (c *Conn) PollForEvent() (Event, Error) {
|
||||
select {
|
||||
case everr := <-c.eventChan:
|
||||
return processEventOrError(everr)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
718
vendor/github.com/BurntSushi/xgb/xinerama/xinerama.go
generated
vendored
718
vendor/github.com/BurntSushi/xgb/xinerama/xinerama.go
generated
vendored
@ -1,718 +0,0 @@
|
||||
// Package xinerama is the X client API for the XINERAMA extension.
|
||||
package xinerama
|
||||
|
||||
// This file is automatically generated from xinerama.xml. Edit at your peril!
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/xgb"
|
||||
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
// Init must be called before using the XINERAMA extension.
|
||||
func Init(c *xgb.Conn) error {
|
||||
reply, err := xproto.QueryExtension(c, 8, "XINERAMA").Reply()
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case !reply.Present:
|
||||
return xgb.Errorf("No extension named XINERAMA could be found on on the server.")
|
||||
}
|
||||
|
||||
c.ExtLock.Lock()
|
||||
c.Extensions["XINERAMA"] = reply.MajorOpcode
|
||||
c.ExtLock.Unlock()
|
||||
for evNum, fun := range xgb.NewExtEventFuncs["XINERAMA"] {
|
||||
xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
|
||||
}
|
||||
for errNum, fun := range xgb.NewExtErrorFuncs["XINERAMA"] {
|
||||
xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
xgb.NewExtEventFuncs["XINERAMA"] = make(map[int]xgb.NewEventFun)
|
||||
xgb.NewExtErrorFuncs["XINERAMA"] = make(map[int]xgb.NewErrorFun)
|
||||
}
|
||||
|
||||
type ScreenInfo struct {
|
||||
XOrg int16
|
||||
YOrg int16
|
||||
Width uint16
|
||||
Height uint16
|
||||
}
|
||||
|
||||
// ScreenInfoRead reads a byte slice into a ScreenInfo value.
|
||||
func ScreenInfoRead(buf []byte, v *ScreenInfo) int {
|
||||
b := 0
|
||||
|
||||
v.XOrg = int16(xgb.Get16(buf[b:]))
|
||||
b += 2
|
||||
|
||||
v.YOrg = int16(xgb.Get16(buf[b:]))
|
||||
b += 2
|
||||
|
||||
v.Width = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Height = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// ScreenInfoReadList reads a byte slice into a list of ScreenInfo values.
|
||||
func ScreenInfoReadList(buf []byte, dest []ScreenInfo) int {
|
||||
b := 0
|
||||
for i := 0; i < len(dest); i++ {
|
||||
dest[i] = ScreenInfo{}
|
||||
b += ScreenInfoRead(buf[b:], &dest[i])
|
||||
}
|
||||
return xgb.Pad(b)
|
||||
}
|
||||
|
||||
// Bytes writes a ScreenInfo value to a byte slice.
|
||||
func (v ScreenInfo) Bytes() []byte {
|
||||
buf := make([]byte, 8)
|
||||
b := 0
|
||||
|
||||
xgb.Put16(buf[b:], uint16(v.XOrg))
|
||||
b += 2
|
||||
|
||||
xgb.Put16(buf[b:], uint16(v.YOrg))
|
||||
b += 2
|
||||
|
||||
xgb.Put16(buf[b:], v.Width)
|
||||
b += 2
|
||||
|
||||
xgb.Put16(buf[b:], v.Height)
|
||||
b += 2
|
||||
|
||||
return buf[:b]
|
||||
}
|
||||
|
||||
// ScreenInfoListBytes writes a list of ScreenInfo values to a byte slice.
|
||||
func ScreenInfoListBytes(buf []byte, list []ScreenInfo) int {
|
||||
b := 0
|
||||
var structBytes []byte
|
||||
for _, item := range list {
|
||||
structBytes = item.Bytes()
|
||||
copy(buf[b:], structBytes)
|
||||
b += len(structBytes)
|
||||
}
|
||||
return xgb.Pad(b)
|
||||
}
|
||||
|
||||
// Skipping definition for base type 'Bool'
|
||||
|
||||
// Skipping definition for base type 'Byte'
|
||||
|
||||
// Skipping definition for base type 'Card8'
|
||||
|
||||
// Skipping definition for base type 'Char'
|
||||
|
||||
// Skipping definition for base type 'Void'
|
||||
|
||||
// Skipping definition for base type 'Double'
|
||||
|
||||
// Skipping definition for base type 'Float'
|
||||
|
||||
// Skipping definition for base type 'Int16'
|
||||
|
||||
// Skipping definition for base type 'Int32'
|
||||
|
||||
// Skipping definition for base type 'Int8'
|
||||
|
||||
// Skipping definition for base type 'Card16'
|
||||
|
||||
// Skipping definition for base type 'Card32'
|
||||
|
||||
// GetScreenCountCookie is a cookie used only for GetScreenCount requests.
|
||||
type GetScreenCountCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// GetScreenCount sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling GetScreenCountCookie.Reply()
|
||||
func GetScreenCount(c *xgb.Conn, Window xproto.Window) GetScreenCountCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetScreenCount' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(getScreenCountRequest(c, Window), cookie)
|
||||
return GetScreenCountCookie{cookie}
|
||||
}
|
||||
|
||||
// GetScreenCountUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func GetScreenCountUnchecked(c *xgb.Conn, Window xproto.Window) GetScreenCountCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetScreenCount' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(getScreenCountRequest(c, Window), cookie)
|
||||
return GetScreenCountCookie{cookie}
|
||||
}
|
||||
|
||||
// GetScreenCountReply represents the data returned from a GetScreenCount request.
|
||||
type GetScreenCountReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
ScreenCount byte
|
||||
Window xproto.Window
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a GetScreenCount request.
|
||||
func (cook GetScreenCountCookie) Reply() (*GetScreenCountReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return getScreenCountReply(buf), nil
|
||||
}
|
||||
|
||||
// getScreenCountReply reads a byte slice into a GetScreenCountReply value.
|
||||
func getScreenCountReply(buf []byte) *GetScreenCountReply {
|
||||
v := new(GetScreenCountReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
v.ScreenCount = buf[b]
|
||||
b += 1
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.Window = xproto.Window(xgb.Get32(buf[b:]))
|
||||
b += 4
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for GetScreenCount
|
||||
// getScreenCountRequest writes a GetScreenCount request to a byte slice.
|
||||
func getScreenCountRequest(c *xgb.Conn, Window xproto.Window) []byte {
|
||||
size := 8
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 2 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
xgb.Put32(buf[b:], uint32(Window))
|
||||
b += 4
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// GetScreenSizeCookie is a cookie used only for GetScreenSize requests.
|
||||
type GetScreenSizeCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// GetScreenSize sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling GetScreenSizeCookie.Reply()
|
||||
func GetScreenSize(c *xgb.Conn, Window xproto.Window, Screen uint32) GetScreenSizeCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetScreenSize' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(getScreenSizeRequest(c, Window, Screen), cookie)
|
||||
return GetScreenSizeCookie{cookie}
|
||||
}
|
||||
|
||||
// GetScreenSizeUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func GetScreenSizeUnchecked(c *xgb.Conn, Window xproto.Window, Screen uint32) GetScreenSizeCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetScreenSize' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(getScreenSizeRequest(c, Window, Screen), cookie)
|
||||
return GetScreenSizeCookie{cookie}
|
||||
}
|
||||
|
||||
// GetScreenSizeReply represents the data returned from a GetScreenSize request.
|
||||
type GetScreenSizeReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
// padding: 1 bytes
|
||||
Width uint32
|
||||
Height uint32
|
||||
Window xproto.Window
|
||||
Screen uint32
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a GetScreenSize request.
|
||||
func (cook GetScreenSizeCookie) Reply() (*GetScreenSizeReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return getScreenSizeReply(buf), nil
|
||||
}
|
||||
|
||||
// getScreenSizeReply reads a byte slice into a GetScreenSizeReply value.
|
||||
func getScreenSizeReply(buf []byte) *GetScreenSizeReply {
|
||||
v := new(GetScreenSizeReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
b += 1 // padding
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.Width = xgb.Get32(buf[b:])
|
||||
b += 4
|
||||
|
||||
v.Height = xgb.Get32(buf[b:])
|
||||
b += 4
|
||||
|
||||
v.Window = xproto.Window(xgb.Get32(buf[b:]))
|
||||
b += 4
|
||||
|
||||
v.Screen = xgb.Get32(buf[b:])
|
||||
b += 4
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for GetScreenSize
|
||||
// getScreenSizeRequest writes a GetScreenSize request to a byte slice.
|
||||
func getScreenSizeRequest(c *xgb.Conn, Window xproto.Window, Screen uint32) []byte {
|
||||
size := 12
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 3 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
xgb.Put32(buf[b:], uint32(Window))
|
||||
b += 4
|
||||
|
||||
xgb.Put32(buf[b:], Screen)
|
||||
b += 4
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// GetStateCookie is a cookie used only for GetState requests.
|
||||
type GetStateCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// GetState sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling GetStateCookie.Reply()
|
||||
func GetState(c *xgb.Conn, Window xproto.Window) GetStateCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetState' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(getStateRequest(c, Window), cookie)
|
||||
return GetStateCookie{cookie}
|
||||
}
|
||||
|
||||
// GetStateUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func GetStateUnchecked(c *xgb.Conn, Window xproto.Window) GetStateCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'GetState' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(getStateRequest(c, Window), cookie)
|
||||
return GetStateCookie{cookie}
|
||||
}
|
||||
|
||||
// GetStateReply represents the data returned from a GetState request.
|
||||
type GetStateReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
State byte
|
||||
Window xproto.Window
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a GetState request.
|
||||
func (cook GetStateCookie) Reply() (*GetStateReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return getStateReply(buf), nil
|
||||
}
|
||||
|
||||
// getStateReply reads a byte slice into a GetStateReply value.
|
||||
func getStateReply(buf []byte) *GetStateReply {
|
||||
v := new(GetStateReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
v.State = buf[b]
|
||||
b += 1
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.Window = xproto.Window(xgb.Get32(buf[b:]))
|
||||
b += 4
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for GetState
|
||||
// getStateRequest writes a GetState request to a byte slice.
|
||||
func getStateRequest(c *xgb.Conn, Window xproto.Window) []byte {
|
||||
size := 8
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 1 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
xgb.Put32(buf[b:], uint32(Window))
|
||||
b += 4
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// IsActiveCookie is a cookie used only for IsActive requests.
|
||||
type IsActiveCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// IsActive sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling IsActiveCookie.Reply()
|
||||
func IsActive(c *xgb.Conn) IsActiveCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'IsActive' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(isActiveRequest(c), cookie)
|
||||
return IsActiveCookie{cookie}
|
||||
}
|
||||
|
||||
// IsActiveUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func IsActiveUnchecked(c *xgb.Conn) IsActiveCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'IsActive' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(isActiveRequest(c), cookie)
|
||||
return IsActiveCookie{cookie}
|
||||
}
|
||||
|
||||
// IsActiveReply represents the data returned from a IsActive request.
|
||||
type IsActiveReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
// padding: 1 bytes
|
||||
State uint32
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a IsActive request.
|
||||
func (cook IsActiveCookie) Reply() (*IsActiveReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return isActiveReply(buf), nil
|
||||
}
|
||||
|
||||
// isActiveReply reads a byte slice into a IsActiveReply value.
|
||||
func isActiveReply(buf []byte) *IsActiveReply {
|
||||
v := new(IsActiveReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
b += 1 // padding
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.State = xgb.Get32(buf[b:])
|
||||
b += 4
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for IsActive
|
||||
// isActiveRequest writes a IsActive request to a byte slice.
|
||||
func isActiveRequest(c *xgb.Conn) []byte {
|
||||
size := 4
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 4 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// QueryScreensCookie is a cookie used only for QueryScreens requests.
|
||||
type QueryScreensCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// QueryScreens sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling QueryScreensCookie.Reply()
|
||||
func QueryScreens(c *xgb.Conn) QueryScreensCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'QueryScreens' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(queryScreensRequest(c), cookie)
|
||||
return QueryScreensCookie{cookie}
|
||||
}
|
||||
|
||||
// QueryScreensUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func QueryScreensUnchecked(c *xgb.Conn) QueryScreensCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'QueryScreens' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(queryScreensRequest(c), cookie)
|
||||
return QueryScreensCookie{cookie}
|
||||
}
|
||||
|
||||
// QueryScreensReply represents the data returned from a QueryScreens request.
|
||||
type QueryScreensReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
// padding: 1 bytes
|
||||
Number uint32
|
||||
// padding: 20 bytes
|
||||
ScreenInfo []ScreenInfo // size: xgb.Pad((int(Number) * 8))
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a QueryScreens request.
|
||||
func (cook QueryScreensCookie) Reply() (*QueryScreensReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return queryScreensReply(buf), nil
|
||||
}
|
||||
|
||||
// queryScreensReply reads a byte slice into a QueryScreensReply value.
|
||||
func queryScreensReply(buf []byte) *QueryScreensReply {
|
||||
v := new(QueryScreensReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
b += 1 // padding
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.Number = xgb.Get32(buf[b:])
|
||||
b += 4
|
||||
|
||||
b += 20 // padding
|
||||
|
||||
v.ScreenInfo = make([]ScreenInfo, v.Number)
|
||||
b += ScreenInfoReadList(buf[b:], v.ScreenInfo)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for QueryScreens
|
||||
// queryScreensRequest writes a QueryScreens request to a byte slice.
|
||||
func queryScreensRequest(c *xgb.Conn) []byte {
|
||||
size := 4
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 5 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// QueryVersionCookie is a cookie used only for QueryVersion requests.
|
||||
type QueryVersionCookie struct {
|
||||
*xgb.Cookie
|
||||
}
|
||||
|
||||
// QueryVersion sends a checked request.
|
||||
// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
|
||||
func QueryVersion(c *xgb.Conn, Major byte, Minor byte) QueryVersionCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(true, true)
|
||||
c.NewRequest(queryVersionRequest(c, Major, Minor), cookie)
|
||||
return QueryVersionCookie{cookie}
|
||||
}
|
||||
|
||||
// QueryVersionUnchecked sends an unchecked request.
|
||||
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
||||
func QueryVersionUnchecked(c *xgb.Conn, Major byte, Minor byte) QueryVersionCookie {
|
||||
c.ExtLock.RLock()
|
||||
defer c.ExtLock.RUnlock()
|
||||
if _, ok := c.Extensions["XINERAMA"]; !ok {
|
||||
panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'XINERAMA'. xinerama.Init(connObj) must be called first.")
|
||||
}
|
||||
cookie := c.NewCookie(false, true)
|
||||
c.NewRequest(queryVersionRequest(c, Major, Minor), cookie)
|
||||
return QueryVersionCookie{cookie}
|
||||
}
|
||||
|
||||
// QueryVersionReply represents the data returned from a QueryVersion request.
|
||||
type QueryVersionReply struct {
|
||||
Sequence uint16 // sequence number of the request for this reply
|
||||
Length uint32 // number of bytes in this reply
|
||||
// padding: 1 bytes
|
||||
Major uint16
|
||||
Minor uint16
|
||||
}
|
||||
|
||||
// Reply blocks and returns the reply data for a QueryVersion request.
|
||||
func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
|
||||
buf, err := cook.Cookie.Reply()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if buf == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return queryVersionReply(buf), nil
|
||||
}
|
||||
|
||||
// queryVersionReply reads a byte slice into a QueryVersionReply value.
|
||||
func queryVersionReply(buf []byte) *QueryVersionReply {
|
||||
v := new(QueryVersionReply)
|
||||
b := 1 // skip reply determinant
|
||||
|
||||
b += 1 // padding
|
||||
|
||||
v.Sequence = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
||||
b += 4
|
||||
|
||||
v.Major = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
v.Minor = xgb.Get16(buf[b:])
|
||||
b += 2
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// Write request to wire for QueryVersion
|
||||
// queryVersionRequest writes a QueryVersion request to a byte slice.
|
||||
func queryVersionRequest(c *xgb.Conn, Major byte, Minor byte) []byte {
|
||||
size := 8
|
||||
b := 0
|
||||
buf := make([]byte, size)
|
||||
|
||||
c.ExtLock.RLock()
|
||||
buf[b] = c.Extensions["XINERAMA"]
|
||||
c.ExtLock.RUnlock()
|
||||
b += 1
|
||||
|
||||
buf[b] = 0 // request opcode
|
||||
b += 1
|
||||
|
||||
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
||||
b += 2
|
||||
|
||||
buf[b] = Major
|
||||
b += 1
|
||||
|
||||
buf[b] = Minor
|
||||
b += 1
|
||||
|
||||
return buf
|
||||
}
|
14910
vendor/github.com/BurntSushi/xgb/xproto/xproto.go
generated
vendored
14910
vendor/github.com/BurntSushi/xgb/xproto/xproto.go
generated
vendored
File diff suppressed because it is too large
Load Diff
6
vendor/github.com/BurntSushi/xgbutil/.gitignore
generated
vendored
6
vendor/github.com/BurntSushi/xgbutil/.gitignore
generated
vendored
@ -1,6 +0,0 @@
|
||||
*.swp
|
||||
*.png
|
||||
tst_first
|
||||
tst_graphics
|
||||
TAGS
|
||||
|
13
vendor/github.com/BurntSushi/xgbutil/COPYING
generated
vendored
13
vendor/github.com/BurntSushi/xgbutil/COPYING
generated
vendored
@ -1,13 +0,0 @@
|
||||
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.
|
36
vendor/github.com/BurntSushi/xgbutil/Makefile
generated
vendored
36
vendor/github.com/BurntSushi/xgbutil/Makefile
generated
vendored
@ -1,36 +0,0 @@
|
||||
all: callback.go types_auto.go gofmt
|
||||
|
||||
install:
|
||||
go install -p 6 . ./ewmh ./gopher ./icccm ./keybind ./motif ./mousebind \
|
||||
./xcursor ./xevent ./xgraphics ./xinerama ./xprop ./xrect ./xwindow
|
||||
|
||||
push:
|
||||
git push origin master
|
||||
git push github master
|
||||
|
||||
build-ex:
|
||||
find ./_examples/ -type d -wholename './_examples/[a-z]*' -print0 \
|
||||
| xargs -0 go build -p 6
|
||||
|
||||
gofmt:
|
||||
gofmt -w *.go */*.go _examples/*/*.go
|
||||
colcheck *.go */*.go _examples/*/*.go
|
||||
|
||||
callback.go:
|
||||
scripts/write-events callbacks > xevent/callback.go
|
||||
|
||||
types_auto.go:
|
||||
scripts/write-events evtypes > xevent/types_auto.go
|
||||
|
||||
tags:
|
||||
find ./ \( -name '*.go' -and -not -wholename './tests/*' -and -not -wholename './_examples/*' \) -print0 | xargs -0 gotags > TAGS
|
||||
|
||||
loc:
|
||||
find ./ -name '*.go' -and -not -wholename './tests*' -and -not -name '*keysymdef.go' -and -not -name '*gopher.go' -print | sort | xargs wc -l
|
||||
|
||||
ex-%:
|
||||
go run _examples/$*/main.go
|
||||
|
||||
gopherimg:
|
||||
go-bindata -f GopherPng -p gopher -i gopher/gophercolor-small.png -o gopher/gopher.go
|
||||
|
60
vendor/github.com/BurntSushi/xgbutil/README
generated
vendored
60
vendor/github.com/BurntSushi/xgbutil/README
generated
vendored
@ -1,60 +0,0 @@
|
||||
xgbutil is a utility library designed to work with the X Go Binding. This
|
||||
project's main goal is to make various X related tasks easier. For example,
|
||||
binding keys, using the EWMH or ICCCM specs with the window manager,
|
||||
moving/resizing windows, assigning function callbacks to particular events,
|
||||
drawing images to a window, etc.
|
||||
|
||||
xgbutil attempts to be thread safe, but it has not been completely tested in
|
||||
this regard. In general, the X event loop implemented in the xevent package is
|
||||
sequential. The idea is to be sequential by default, and let the user spawn
|
||||
concurrent code at their discretion. (i.e., the complexity of making the main
|
||||
event loop generally concurrent is vast.)
|
||||
|
||||
You may sleep safely at night by assuming that XGB is thread safe, though.
|
||||
|
||||
To start using xgbutil, you should have at least a passing familiarity with X.
|
||||
Your first stop should be the examples directory.
|
||||
|
||||
Installation
|
||||
============
|
||||
go get github.com/BurntSushi/xgbutil
|
||||
|
||||
Dependencies
|
||||
============
|
||||
XGB is the main dependency. Use of the xgraphics packages requires graphics-go
|
||||
and freetype-go.
|
||||
|
||||
XGB project URL: https://github.com/BurntSushi/xgb
|
||||
|
||||
Quick Example
|
||||
=============
|
||||
go get github.com/BurntSushi/xgbutil/_examples/window-name-sizes
|
||||
"$GOPATH"/bin/window-name-sizes
|
||||
|
||||
The output will be a list of names of all top-level windows and their geometry
|
||||
including window manager decorations. (Assuming your window manager supports
|
||||
some basic EWMH properties.)
|
||||
|
||||
Documentation
|
||||
=============
|
||||
gopkgdoc is well-suited to provide documentation for xgbutil. Its cross-package
|
||||
hyperlinking on types is also extremely useful, since much of xgbutil relies on
|
||||
XGB.
|
||||
|
||||
With that said, documentation is also hosted here:
|
||||
http://godoc.burntsushi.net/pkg/github.com/BurntSushi/xgbutil/
|
||||
|
||||
Examples
|
||||
========
|
||||
There are several examples in the examples directory covering common use cases.
|
||||
They are heavily documented and should run out of the box.
|
||||
|
||||
Python
|
||||
======
|
||||
An older project of mine, xpybutil, served as inspiration for xgbutil. If you
|
||||
want to use Python, xpybutil should help quite a bit. Please note though, that
|
||||
at this point, xgbutil provides a lot more functionality and is much better
|
||||
documented.
|
||||
|
||||
xpybutil project URL: https://github.com/BurntSushi/xpybutil
|
||||
|
29
vendor/github.com/BurntSushi/xgbutil/STYLE
generated
vendored
29
vendor/github.com/BurntSushi/xgbutil/STYLE
generated
vendored
@ -1,29 +0,0 @@
|
||||
I like to keep all my code to 80 columns or less. I have plenty of screen real
|
||||
estate, but enjoy 80 columns so that I can have multiple code windows open side
|
||||
to side and not be plagued by the ugly auto-wrapping of a text editor.
|
||||
|
||||
If you don't oblige me, I will fix any patch you submit to abide 80 columns.
|
||||
|
||||
Note that this style restriction does not preclude gofmt, but introduces a few
|
||||
peculiarities. The first is that gofmt will occasionally add spacing (typically
|
||||
to comments) that ends up going over 80 columns. Either shorten the comment or
|
||||
put it on its own line.
|
||||
|
||||
The second and more common hiccup is when a function definition extends beyond
|
||||
80 columns. If one adds line breaks to keep it below 80 columns, gofmt will
|
||||
indent all subsequent lines in a function definition to the same indentation
|
||||
level of the function body. This results in a less-than-ideal separation
|
||||
between function definition and function body. To remedy this, simply add a
|
||||
line break like so:
|
||||
|
||||
func RestackWindowExtra(xu *xgbutil.XUtil, win xproto.Window, stackMode int,
|
||||
sibling xproto.Window, source int) error {
|
||||
|
||||
return ClientEvent(xu, win, "_NET_RESTACK_WINDOW", source, int(sibling),
|
||||
stackMode)
|
||||
}
|
||||
|
||||
Something similar should also be applied to long 'if' or 'for' conditionals,
|
||||
although it would probably be preferrable to break up the conditional to
|
||||
smaller chunks with a few helper variables.
|
||||
|
67
vendor/github.com/BurntSushi/xgbutil/doc.go
generated
vendored
67
vendor/github.com/BurntSushi/xgbutil/doc.go
generated
vendored
@ -1,67 +0,0 @@
|
||||
/*
|
||||
Package xgbutil is a utility library designed to make common tasks with the X
|
||||
server easier. The central design choice that has driven development is to hide
|
||||
the complexity of X wherever possible but expose it when necessary.
|
||||
|
||||
For example, the xevent package provides an implementation of an X event loop
|
||||
that acts as a dispatcher to event handlers set up with the xevent, keybind and
|
||||
mousebind packages. At the same time, the event queue is exposed and can be
|
||||
modified using xevent.Peek and xevent.DequeueAt.
|
||||
|
||||
Sub-packages
|
||||
|
||||
The xgbutil package is considerably small, and only contains some type
|
||||
definitions and the initial setup for an X connection. Much of the
|
||||
functionality of xgbutil comes from its sub-packages. Each sub-package is
|
||||
appropriately documented.
|
||||
|
||||
Installation
|
||||
|
||||
xgbutil is go-gettable:
|
||||
|
||||
go get github.com/BurntSushi/xgbutil
|
||||
|
||||
Dependencies
|
||||
|
||||
XGB is the main dependency, and is required for all packages inside xgbutil.
|
||||
|
||||
graphics-go and freetype-go are also required if using the xgraphics package.
|
||||
|
||||
Quick Example
|
||||
|
||||
A quick example to demonstrate that xgbutil is working correctly:
|
||||
|
||||
go get github.com/BurntSushi/xgbutil/examples/window-name-sizes
|
||||
GO/PATH/bin/window-name-sizes
|
||||
|
||||
The output will be a list of names of all top-level windows and their geometry
|
||||
including window manager decorations. (Assuming your window manager supports
|
||||
some basic EWMH properties.)
|
||||
|
||||
Examples
|
||||
|
||||
The examples directory contains a sizable number of examples demonstrating
|
||||
common tasks with X. They are intended to demonstrate a single thing each,
|
||||
although a few that require setup are necessarily long. Each example is
|
||||
heavily documented.
|
||||
|
||||
The examples directory should be your first stop when learning how to use
|
||||
xgbutil.
|
||||
|
||||
xgbutil is also used heavily throughout my window manager, Wingo. It may be
|
||||
useful reference material.
|
||||
|
||||
Wingo project page: https://github.com/BurntSushi/wingo
|
||||
|
||||
Thread Safety
|
||||
|
||||
While I am fairly confident that XGB is thread safe, I am only somewhat
|
||||
confident that xgbutil is thread safe. It simply has not been tested enough for
|
||||
my confidence to be higher.
|
||||
|
||||
Note that the xevent package's X event loop is not concurrent. Namely,
|
||||
designing a generally concurrent X event loop is extremely complex. Instead,
|
||||
the onus is on you, the user, to design concurrent callback functions if
|
||||
concurrency is desired.
|
||||
*/
|
||||
package xgbutil
|
56
vendor/github.com/BurntSushi/xgbutil/ewmh/doc.go
generated
vendored
56
vendor/github.com/BurntSushi/xgbutil/ewmh/doc.go
generated
vendored
@ -1,56 +0,0 @@
|
||||
/*
|
||||
Package ewmh provides a comprehensive API to get and set properties specified
|
||||
by the EWMH spec, as well as perform actions specified by the EWMH spec.
|
||||
|
||||
Since there are so many functions and they adhere to an existing spec,
|
||||
this package file does not contain much documentation. Indeed, each
|
||||
method has only a single comment associated with it: the EWMH property name.
|
||||
|
||||
The idea is to
|
||||
provide a consistent interface to use all facilities described in the EWMH
|
||||
spec: http://standards.freedesktop.org/wm-spec/wm-spec-latest.html.
|
||||
|
||||
Naming scheme
|
||||
|
||||
Using "_NET_ACTIVE_WINDOW" as an example,
|
||||
functions "ActiveWindowGet" and "ActiveWindowSet" get and set the
|
||||
property, respectively. Both of these functions exist for most EWMH
|
||||
properties. Additionally, some EWMH properties support sending a client
|
||||
message event to request the window manager to perform some action. In the
|
||||
case of "_NET_ACTIVE_WINDOW", this request is used to set the active
|
||||
window.
|
||||
|
||||
These sorts of functions end in "Req". So for "_NET_ACTIVE_WINDOW",
|
||||
the method name is "ActiveWindowReq". Moreover, most requests include
|
||||
various parameters that don't need to be changed often (like the source
|
||||
indication). Thus, by default, functions ending in "Req" force these to
|
||||
sensible defaults. If you need access to all of the parameters, use the
|
||||
corresponding "ReqExtra" method. So for "_NET_ACTIVE_WINDOW", that would
|
||||
be "ActiveWindowReqExtra". (If no "ReqExtra" method exists, then the
|
||||
"Req" method covers all available parameters.)
|
||||
|
||||
This naming scheme has one exception: if a property's only use is through
|
||||
sending an event (like "_NET_CLOSE_WINDOW"), then the name will be
|
||||
"CloseWindow" for the short-hand version and "CloseWindowExtra"
|
||||
for access to all of the parameters. (Since there is no "_NET_CLOSE_WINDOW"
|
||||
property, there is no need for "CloseWindowGet" and "CloseWindowSet"
|
||||
functions.)
|
||||
|
||||
For properties that store more than just a simple integer, name or list
|
||||
of integers, structs have been created and exposed to organize the
|
||||
information returned in a sensible manner. For example, the
|
||||
"_NET_DESKTOP_GEOMETRY" property would typically return a slice of integers
|
||||
of length 2, where the first integer is the width and the second is the
|
||||
height. Xgbutil will wrap this in a struct with the obvious members. These
|
||||
structs are documented.
|
||||
|
||||
Finally, functions ending in "*Set" are typically only used when setting
|
||||
properties on clients *you've* created or when the window manager sets
|
||||
properties. Thus, it's unlikely that you should use them unless you're
|
||||
creating a top-level client or building a window manager.
|
||||
|
||||
Functions ending in "Get" or "Req[Extra]" are commonly used.
|
||||
|
||||
N.B. Not all properties have "*Req" functions.
|
||||
*/
|
||||
package ewmh
|
1159
vendor/github.com/BurntSushi/xgbutil/ewmh/ewmh.go
generated
vendored
1159
vendor/github.com/BurntSushi/xgbutil/ewmh/ewmh.go
generated
vendored
File diff suppressed because it is too large
Load Diff
31
vendor/github.com/BurntSushi/xgbutil/ewmh/winman.go
generated
vendored
31
vendor/github.com/BurntSushi/xgbutil/ewmh/winman.go
generated
vendored
@ -1,31 +0,0 @@
|
||||
package ewmh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
// GetEwmhWM uses the EWMH spec to find if a conforming window manager
|
||||
// is currently running or not. If it is, then its name will be returned.
|
||||
// Otherwise, an error will be returned explaining why one couldn't be found.
|
||||
func GetEwmhWM(xu *xgbutil.XUtil) (string, error) {
|
||||
childCheck, err := SupportingWmCheckGet(xu, xu.RootWin())
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
|
||||
}
|
||||
|
||||
childCheck2, err := SupportingWmCheckGet(xu, childCheck)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("GetEwmhWM: Failed because: %s", err)
|
||||
}
|
||||
|
||||
if childCheck != childCheck2 {
|
||||
return "", fmt.Errorf(
|
||||
"GetEwmhWM: _NET_SUPPORTING_WM_CHECK value on the root window "+
|
||||
"(%x) does not match _NET_SUPPORTING_WM_CHECK value "+
|
||||
"on the child window (%x).", childCheck, childCheck2)
|
||||
}
|
||||
|
||||
return WmNameGet(xu, childCheck)
|
||||
}
|
1
vendor/github.com/BurntSushi/xgbutil/session.vim
generated
vendored
1
vendor/github.com/BurntSushi/xgbutil/session.vim
generated
vendored
@ -1 +0,0 @@
|
||||
au BufWritePost *.go silent!make tags > /dev/null 2>&1
|
167
vendor/github.com/BurntSushi/xgbutil/types.go
generated
vendored
167
vendor/github.com/BurntSushi/xgbutil/types.go
generated
vendored
@ -1,167 +0,0 @@
|
||||
package xgbutil
|
||||
|
||||
/*
|
||||
types.go contains several types used in the XUtil structure. In an ideal world,
|
||||
they would be defined in their appropriate packages, but must be defined here
|
||||
(and exported) for use in some sub-packages. (Namely, xevent, keybind and
|
||||
mousebind.)
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
// Callback is an interface that should be implemented by event callback
|
||||
// functions. Namely, to assign a function to a particular event/window
|
||||
// combination, simply define a function with type 'SomeEventFun' (pre-defined
|
||||
// in xevent/callback.go), and call the 'Connect' method.
|
||||
// The 'Run' method is used inside the Main event loop, and shouldn't be used
|
||||
// by the user.
|
||||
// Also, it is perfectly legitimate to connect to events that don't specify
|
||||
// a window (like MappingNotify and KeymapNotify). In this case, simply
|
||||
// use 'xgbutil.NoWindow' as the window id.
|
||||
//
|
||||
// Example to respond to ConfigureNotify events on window 0x1
|
||||
//
|
||||
// xevent.ConfigureNotifyFun(
|
||||
// func(X *xgbutil.XUtil, e xevent.ConfigureNotifyEvent) {
|
||||
// fmt.Printf("(%d, %d) %dx%d\n", e.X, e.Y, e.Width, e.Height)
|
||||
// }).Connect(X, 0x1)
|
||||
type Callback interface {
|
||||
// Connect modifies XUtil's state to attach an event handler to a
|
||||
// particular event.
|
||||
Connect(xu *XUtil, win xproto.Window)
|
||||
|
||||
// Run is exported for use in the xevent package but should not be
|
||||
// used by the user. (It is used to run the callback function in the
|
||||
// main event loop.)
|
||||
Run(xu *XUtil, ev interface{})
|
||||
}
|
||||
|
||||
// CallbackHook works similarly to the more general Callback, but it is
|
||||
// for hooks into the main xevent loop. As such it does not get attached
|
||||
// to a window.
|
||||
type CallbackHook interface {
|
||||
// Connect connects this hook to the main loop of the passed XUtil
|
||||
// instance.
|
||||
Connect(xu *XUtil)
|
||||
|
||||
// Run is exported for use in the xevent package, but should not be
|
||||
// used by the user. It should return true if it's ok to process
|
||||
// the event as usual, or false if it should be suppressed.
|
||||
Run(xu *XUtil, ev interface{}) bool
|
||||
}
|
||||
|
||||
// CallbackKey works similarly to the more general Callback, but it adds
|
||||
// parameters specific to key bindings.
|
||||
type CallbackKey interface {
|
||||
// Connect modifies XUtil's state to attach an event handler to a
|
||||
// particular key press. If grab is true, connect will request a passive
|
||||
// grab.
|
||||
Connect(xu *XUtil, win xproto.Window, keyStr string, grab bool) error
|
||||
|
||||
// Run is exported for use in the keybind package but should not be
|
||||
// used by the user. (It is used to run the callback function in the
|
||||
// main event loop.
|
||||
Run(xu *XUtil, ev interface{})
|
||||
}
|
||||
|
||||
// CallbackMouse works similarly to the more general Callback, but it adds
|
||||
// parameters specific to mouse bindings.
|
||||
type CallbackMouse interface {
|
||||
// Connect modifies XUtil's state to attach an event handler to a
|
||||
// particular button press.
|
||||
// If sync is true, the grab will be synchronous. (This will require a
|
||||
// call to xproto.AllowEvents in response, otherwise no further events
|
||||
// will be processed and your program will lock.)
|
||||
// If grab is true, connect will request a passive grab.
|
||||
Connect(xu *XUtil, win xproto.Window, buttonStr string,
|
||||
sync bool, grab bool) error
|
||||
|
||||
// Run is exported for use in the mousebind package but should not be
|
||||
// used by the user. (It is used to run the callback function in the
|
||||
// main event loop.)
|
||||
Run(xu *XUtil, ev interface{})
|
||||
}
|
||||
|
||||
// KeyKey is the type of the key in the map of keybindings.
|
||||
// It essentially represents the tuple
|
||||
// (event type, window id, modifier, keycode).
|
||||
// It is exported for use in the keybind package. It should not be used.
|
||||
type KeyKey struct {
|
||||
Evtype int
|
||||
Win xproto.Window
|
||||
Mod uint16
|
||||
Code xproto.Keycode
|
||||
}
|
||||
|
||||
// KeyString is the type of a key binding string used to connect to particular
|
||||
// key combinations. A list of all such key strings is maintained in order to
|
||||
// rebind keys when the keyboard mapping has been changed.
|
||||
type KeyString struct {
|
||||
Str string
|
||||
Callback CallbackKey
|
||||
Evtype int
|
||||
Win xproto.Window
|
||||
Grab bool
|
||||
}
|
||||
|
||||
// MouseKey is the type of the key in the map of mouse bindings.
|
||||
// It essentially represents the tuple
|
||||
// (event type, window id, modifier, button).
|
||||
// It is exported for use in the mousebind package. It should not be used.
|
||||
type MouseKey struct {
|
||||
Evtype int
|
||||
Win xproto.Window
|
||||
Mod uint16
|
||||
Button xproto.Button
|
||||
}
|
||||
|
||||
// KeyboardMapping embeds a keyboard mapping reply from XGB.
|
||||
// It should be retrieved using keybind.KeyMapGet, if necessary.
|
||||
// xgbutil tries quite hard to absolve you from ever having to use this.
|
||||
// A keyboard mapping is a table that maps keycodes to one or more keysyms.
|
||||
type KeyboardMapping struct {
|
||||
*xproto.GetKeyboardMappingReply
|
||||
}
|
||||
|
||||
// ModifierMapping embeds a modifier mapping reply from XGB.
|
||||
// It should be retrieved using keybind.ModMapGet, if necessary.
|
||||
// xgbutil tries quite hard to absolve you from ever having to use this.
|
||||
// A modifier mapping is a table that maps modifiers to one or more keycodes.
|
||||
type ModifierMapping struct {
|
||||
*xproto.GetModifierMappingReply
|
||||
}
|
||||
|
||||
// ErrorHandlerFun is the type of function required to handle errors that
|
||||
// come in through the main event loop.
|
||||
// For example, to set a new error handler, use:
|
||||
//
|
||||
// xevent.ErrorHandlerSet(xgbutil.ErrorHandlerFun(
|
||||
// func(err xgb.Error) {
|
||||
// // do something with err
|
||||
// }))
|
||||
type ErrorHandlerFun func(err xgb.Error)
|
||||
|
||||
// EventOrError is a struct that contains either an event value or an error
|
||||
// value. It is an error to contain both. Containing neither indicates an
|
||||
// error too.
|
||||
// This is exported for use in the xevent package. You shouldn't have any
|
||||
// direct contact with values of this type, unless you need to inspect the
|
||||
// queue directly with xevent.Peek.
|
||||
type EventOrError struct {
|
||||
Event xgb.Event
|
||||
Err xgb.Error
|
||||
}
|
||||
|
||||
// MouseDragFun is the kind of function used on each dragging step
|
||||
// and at the end of a drag.
|
||||
type MouseDragFun func(xu *XUtil, rootX, rootY, eventX, eventY int)
|
||||
|
||||
// MouseDragBeginFun is the kind of function used to initialize a drag.
|
||||
// The difference between this and MouseDragFun is that the begin function
|
||||
// returns a bool (of whether or not to cancel the drag) and an X resource
|
||||
// identifier corresponding to a cursor.
|
||||
type MouseDragBeginFun func(xu *XUtil, rootX, rootY,
|
||||
eventX, eventY int) (bool, xproto.Cursor)
|
389
vendor/github.com/BurntSushi/xgbutil/xevent/callback.go
generated
vendored
389
vendor/github.com/BurntSushi/xgbutil/xevent/callback.go
generated
vendored
@ -1,389 +0,0 @@
|
||||
package xevent
|
||||
|
||||
/*
|
||||
Does all the plumbing to allow a simple callback interface for users.
|
||||
|
||||
This file is automatically generated using `scripts/write-events callbacks`.
|
||||
|
||||
Edit it at your peril.
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
type KeyPressFun func(xu *xgbutil.XUtil, event KeyPressEvent)
|
||||
|
||||
func (callback KeyPressFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, KeyPress, win, callback)
|
||||
}
|
||||
|
||||
func (callback KeyPressFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(KeyPressEvent))
|
||||
}
|
||||
|
||||
type KeyReleaseFun func(xu *xgbutil.XUtil, event KeyReleaseEvent)
|
||||
|
||||
func (callback KeyReleaseFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, KeyRelease, win, callback)
|
||||
}
|
||||
|
||||
func (callback KeyReleaseFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(KeyReleaseEvent))
|
||||
}
|
||||
|
||||
type ButtonPressFun func(xu *xgbutil.XUtil, event ButtonPressEvent)
|
||||
|
||||
func (callback ButtonPressFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ButtonPress, win, callback)
|
||||
}
|
||||
|
||||
func (callback ButtonPressFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ButtonPressEvent))
|
||||
}
|
||||
|
||||
type ButtonReleaseFun func(xu *xgbutil.XUtil, event ButtonReleaseEvent)
|
||||
|
||||
func (callback ButtonReleaseFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ButtonRelease, win, callback)
|
||||
}
|
||||
|
||||
func (callback ButtonReleaseFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ButtonReleaseEvent))
|
||||
}
|
||||
|
||||
type MotionNotifyFun func(xu *xgbutil.XUtil, event MotionNotifyEvent)
|
||||
|
||||
func (callback MotionNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, MotionNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback MotionNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(MotionNotifyEvent))
|
||||
}
|
||||
|
||||
type EnterNotifyFun func(xu *xgbutil.XUtil, event EnterNotifyEvent)
|
||||
|
||||
func (callback EnterNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, EnterNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback EnterNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(EnterNotifyEvent))
|
||||
}
|
||||
|
||||
type LeaveNotifyFun func(xu *xgbutil.XUtil, event LeaveNotifyEvent)
|
||||
|
||||
func (callback LeaveNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, LeaveNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback LeaveNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(LeaveNotifyEvent))
|
||||
}
|
||||
|
||||
type FocusInFun func(xu *xgbutil.XUtil, event FocusInEvent)
|
||||
|
||||
func (callback FocusInFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, FocusIn, win, callback)
|
||||
}
|
||||
|
||||
func (callback FocusInFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(FocusInEvent))
|
||||
}
|
||||
|
||||
type FocusOutFun func(xu *xgbutil.XUtil, event FocusOutEvent)
|
||||
|
||||
func (callback FocusOutFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, FocusOut, win, callback)
|
||||
}
|
||||
|
||||
func (callback FocusOutFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(FocusOutEvent))
|
||||
}
|
||||
|
||||
type KeymapNotifyFun func(xu *xgbutil.XUtil, event KeymapNotifyEvent)
|
||||
|
||||
func (callback KeymapNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, KeymapNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback KeymapNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(KeymapNotifyEvent))
|
||||
}
|
||||
|
||||
type ExposeFun func(xu *xgbutil.XUtil, event ExposeEvent)
|
||||
|
||||
func (callback ExposeFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, Expose, win, callback)
|
||||
}
|
||||
|
||||
func (callback ExposeFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ExposeEvent))
|
||||
}
|
||||
|
||||
type GraphicsExposureFun func(xu *xgbutil.XUtil, event GraphicsExposureEvent)
|
||||
|
||||
func (callback GraphicsExposureFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, GraphicsExposure, win, callback)
|
||||
}
|
||||
|
||||
func (callback GraphicsExposureFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(GraphicsExposureEvent))
|
||||
}
|
||||
|
||||
type NoExposureFun func(xu *xgbutil.XUtil, event NoExposureEvent)
|
||||
|
||||
func (callback NoExposureFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, NoExposure, win, callback)
|
||||
}
|
||||
|
||||
func (callback NoExposureFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(NoExposureEvent))
|
||||
}
|
||||
|
||||
type VisibilityNotifyFun func(xu *xgbutil.XUtil, event VisibilityNotifyEvent)
|
||||
|
||||
func (callback VisibilityNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, VisibilityNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback VisibilityNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(VisibilityNotifyEvent))
|
||||
}
|
||||
|
||||
type CreateNotifyFun func(xu *xgbutil.XUtil, event CreateNotifyEvent)
|
||||
|
||||
func (callback CreateNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, CreateNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback CreateNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(CreateNotifyEvent))
|
||||
}
|
||||
|
||||
type DestroyNotifyFun func(xu *xgbutil.XUtil, event DestroyNotifyEvent)
|
||||
|
||||
func (callback DestroyNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, DestroyNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback DestroyNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(DestroyNotifyEvent))
|
||||
}
|
||||
|
||||
type UnmapNotifyFun func(xu *xgbutil.XUtil, event UnmapNotifyEvent)
|
||||
|
||||
func (callback UnmapNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, UnmapNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback UnmapNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(UnmapNotifyEvent))
|
||||
}
|
||||
|
||||
type MapNotifyFun func(xu *xgbutil.XUtil, event MapNotifyEvent)
|
||||
|
||||
func (callback MapNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, MapNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback MapNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(MapNotifyEvent))
|
||||
}
|
||||
|
||||
type MapRequestFun func(xu *xgbutil.XUtil, event MapRequestEvent)
|
||||
|
||||
func (callback MapRequestFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, MapRequest, win, callback)
|
||||
}
|
||||
|
||||
func (callback MapRequestFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(MapRequestEvent))
|
||||
}
|
||||
|
||||
type ReparentNotifyFun func(xu *xgbutil.XUtil, event ReparentNotifyEvent)
|
||||
|
||||
func (callback ReparentNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ReparentNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback ReparentNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ReparentNotifyEvent))
|
||||
}
|
||||
|
||||
type ConfigureNotifyFun func(xu *xgbutil.XUtil, event ConfigureNotifyEvent)
|
||||
|
||||
func (callback ConfigureNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ConfigureNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback ConfigureNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ConfigureNotifyEvent))
|
||||
}
|
||||
|
||||
type ConfigureRequestFun func(xu *xgbutil.XUtil, event ConfigureRequestEvent)
|
||||
|
||||
func (callback ConfigureRequestFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ConfigureRequest, win, callback)
|
||||
}
|
||||
|
||||
func (callback ConfigureRequestFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ConfigureRequestEvent))
|
||||
}
|
||||
|
||||
type GravityNotifyFun func(xu *xgbutil.XUtil, event GravityNotifyEvent)
|
||||
|
||||
func (callback GravityNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, GravityNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback GravityNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(GravityNotifyEvent))
|
||||
}
|
||||
|
||||
type ResizeRequestFun func(xu *xgbutil.XUtil, event ResizeRequestEvent)
|
||||
|
||||
func (callback ResizeRequestFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ResizeRequest, win, callback)
|
||||
}
|
||||
|
||||
func (callback ResizeRequestFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ResizeRequestEvent))
|
||||
}
|
||||
|
||||
type CirculateNotifyFun func(xu *xgbutil.XUtil, event CirculateNotifyEvent)
|
||||
|
||||
func (callback CirculateNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, CirculateNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback CirculateNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(CirculateNotifyEvent))
|
||||
}
|
||||
|
||||
type CirculateRequestFun func(xu *xgbutil.XUtil, event CirculateRequestEvent)
|
||||
|
||||
func (callback CirculateRequestFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, CirculateRequest, win, callback)
|
||||
}
|
||||
|
||||
func (callback CirculateRequestFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(CirculateRequestEvent))
|
||||
}
|
||||
|
||||
type PropertyNotifyFun func(xu *xgbutil.XUtil, event PropertyNotifyEvent)
|
||||
|
||||
func (callback PropertyNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, PropertyNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback PropertyNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(PropertyNotifyEvent))
|
||||
}
|
||||
|
||||
type SelectionClearFun func(xu *xgbutil.XUtil, event SelectionClearEvent)
|
||||
|
||||
func (callback SelectionClearFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, SelectionClear, win, callback)
|
||||
}
|
||||
|
||||
func (callback SelectionClearFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(SelectionClearEvent))
|
||||
}
|
||||
|
||||
type SelectionRequestFun func(xu *xgbutil.XUtil, event SelectionRequestEvent)
|
||||
|
||||
func (callback SelectionRequestFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, SelectionRequest, win, callback)
|
||||
}
|
||||
|
||||
func (callback SelectionRequestFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(SelectionRequestEvent))
|
||||
}
|
||||
|
||||
type SelectionNotifyFun func(xu *xgbutil.XUtil, event SelectionNotifyEvent)
|
||||
|
||||
func (callback SelectionNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, SelectionNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback SelectionNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(SelectionNotifyEvent))
|
||||
}
|
||||
|
||||
type ColormapNotifyFun func(xu *xgbutil.XUtil, event ColormapNotifyEvent)
|
||||
|
||||
func (callback ColormapNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ColormapNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback ColormapNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ColormapNotifyEvent))
|
||||
}
|
||||
|
||||
type ClientMessageFun func(xu *xgbutil.XUtil, event ClientMessageEvent)
|
||||
|
||||
func (callback ClientMessageFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ClientMessage, win, callback)
|
||||
}
|
||||
|
||||
func (callback ClientMessageFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ClientMessageEvent))
|
||||
}
|
||||
|
||||
type MappingNotifyFun func(xu *xgbutil.XUtil, event MappingNotifyEvent)
|
||||
|
||||
func (callback MappingNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, MappingNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback MappingNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(MappingNotifyEvent))
|
||||
}
|
||||
|
||||
type ShapeNotifyFun func(xu *xgbutil.XUtil, event ShapeNotifyEvent)
|
||||
|
||||
func (callback ShapeNotifyFun) Connect(xu *xgbutil.XUtil,
|
||||
win xproto.Window) {
|
||||
attachCallback(xu, ShapeNotify, win, callback)
|
||||
}
|
||||
|
||||
func (callback ShapeNotifyFun) Run(xu *xgbutil.XUtil, event interface{}) {
|
||||
callback(xu, event.(ShapeNotifyEvent))
|
||||
}
|
76
vendor/github.com/BurntSushi/xgbutil/xevent/doc.go
generated
vendored
76
vendor/github.com/BurntSushi/xgbutil/xevent/doc.go
generated
vendored
@ -1,76 +0,0 @@
|
||||
/*
|
||||
Package xevent provides an event handler interface for attaching callback
|
||||
functions to X events, and an implementation of an X event loop.
|
||||
|
||||
The X event loop
|
||||
|
||||
One of the biggest conveniences offered by xgbutil is its event handler system.
|
||||
That is, the ability to attach an arbitrary callback function to any X event.
|
||||
In order for such things to work, xgbutil needs to control the main X event
|
||||
loop and act as a dispatcher for all event handlers created by you.
|
||||
|
||||
To run the X event loop, use xevent.Main or xevent.MainPing. The former
|
||||
runs a normal event loop in the current goroutine and processes events. The
|
||||
latter runs the event loop in a new goroutine and returns a pingBefore and
|
||||
a pingAfter channel. The pingBefore channel is sent a benign value right before
|
||||
an event is dequeued, and the pingAfter channel is sent a benign value right
|
||||
after after all callbacks for that event have finished execution. These
|
||||
synchronization points in the main event loop can be combined with a 'select'
|
||||
statement to process data from other input sources. An example of this is given
|
||||
in the documentation for the MainPing function. A complete example called
|
||||
multiple-source-event-loop can also be found in the examples directory of the
|
||||
xgbutil package.
|
||||
|
||||
To quit the main event loop, you may use xevent.Quit, but there is nothing
|
||||
inherently wrong with stopping dead using os.Exit. xevent.Quit is provided for
|
||||
your convenience should you need to run any clean-up code after the main event
|
||||
loop returns.
|
||||
|
||||
The X event queue
|
||||
|
||||
xgbutil's event queue contains values that are either events or errors. (Never
|
||||
both and never neither.) Namely, errors are received in the event loop from
|
||||
unchecked requests. (Errors generated by checked requests are guaranteed to be
|
||||
returned to the caller and are never received in the event loop.) Also, a
|
||||
default error handler function can be set with xevent.ErrorHandlerSet.
|
||||
|
||||
To this end, xgbutil's event queue can be inspected. This is advantageous when
|
||||
information about what events will be processed in the future could be helpful
|
||||
(i.e., if there is an UnmapNotify event waiting to be processed.) The event
|
||||
queue can also be manipulated to facilitate event compression. (Two events that
|
||||
are common candidates for compression are ConfigureNotify and MotionNotify.)
|
||||
|
||||
Detach events
|
||||
|
||||
Whenever a window can no longer receive events (i.e., when it is destroyed),
|
||||
all event handlers related to that window should be detached. (If this is
|
||||
omitted, then Go's garbage collector will not be able to reuse memory occupied
|
||||
by the now-unused event handlers for that window.) Moreover, its possible that
|
||||
a window id can be reused after it has been discarded, which could result in
|
||||
odd behavior in your application.
|
||||
|
||||
To detach a window from all event handlers in the xevent package, use
|
||||
xevent.Detach. If you're also using the keybind and mousebind packages, you'll
|
||||
need to call keybind.Detach and mousebind.Detach too. So to detach your window
|
||||
from all possible event handlers in xgbutil, use something like:
|
||||
|
||||
xevent.Detach(XUtilValue, your-window-id)
|
||||
keybind.Detach(XUtilValue, your-window-id)
|
||||
mousebind.Detach(XUtilValue, your-window-id)
|
||||
|
||||
Quick example
|
||||
|
||||
A small example that shows how to respond to ConfigureNotify events sent to
|
||||
your-window-id.
|
||||
|
||||
xevent.ConfigureNotifyFun(
|
||||
func(X *xgbutil.XUtil, e xevent.ConfigureNotifyEvent) {
|
||||
fmt.Printf("(%d, %d) %dx%d\n", e.X, e.Y, e.Width, e.Height)
|
||||
}).Connect(XUtilValue, your-window-id)
|
||||
|
||||
More examples
|
||||
|
||||
The xevent package is used in several of the examples in the examples directory
|
||||
in the xgbutil package.
|
||||
*/
|
||||
package xevent
|
291
vendor/github.com/BurntSushi/xgbutil/xevent/eventloop.go
generated
vendored
291
vendor/github.com/BurntSushi/xgbutil/xevent/eventloop.go
generated
vendored
@ -1,291 +0,0 @@
|
||||
package xevent
|
||||
|
||||
/*
|
||||
xevent/eventloop.go contains code that implements a main X event loop.
|
||||
|
||||
Namely, it provides facilities to read new events into xevent's event queue,
|
||||
run a normal main event loop and run a main event loop that pings a channel
|
||||
each time an event is about to be dequeued. The latter facility allows one to
|
||||
easily include other input sources for processing in a program's main event
|
||||
loop.
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/xgb/shape"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
// Read reads one or more events and queues them in XUtil.
|
||||
// If 'block' is True, then call 'WaitForEvent' before sucking up
|
||||
// all events that have been queued by XGB.
|
||||
func Read(xu *xgbutil.XUtil, block bool) {
|
||||
if block {
|
||||
ev, err := xu.Conn().WaitForEvent()
|
||||
if ev == nil && err == nil {
|
||||
xgbutil.Logger.Fatal("BUG: Could not read an event or an error.")
|
||||
}
|
||||
Enqueue(xu, ev, err)
|
||||
}
|
||||
|
||||
// Clean up anything that's in the queue
|
||||
for {
|
||||
ev, err := xu.Conn().PollForEvent()
|
||||
|
||||
// No events left...
|
||||
if ev == nil && err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
// We're good, queue it up
|
||||
Enqueue(xu, ev, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Main starts the main X event loop. It will read events and call appropriate
|
||||
// callback functions.
|
||||
// N.B. If you have multiple X connections in the same program, you should be
|
||||
// able to run this in different goroutines concurrently. However, only
|
||||
// *one* of these should run for *each* connection.
|
||||
func Main(xu *xgbutil.XUtil) {
|
||||
mainEventLoop(xu, nil, nil, nil)
|
||||
}
|
||||
|
||||
// MainPing starts the main X event loop, and returns three "ping" channels:
|
||||
// the first is pinged before an event is dequeued, the second is pinged
|
||||
// after all callbacks for a particular event have been called and the last
|
||||
// is pinged when the event loop stops (e.g., after a call to xevent.Quit).
|
||||
// pingAfter channel.
|
||||
//
|
||||
// This is useful if your event loop needs to draw from other sources. e.g.,
|
||||
//
|
||||
// pingBefore, pingAfter, pingQuit := xevent.MainPing()
|
||||
// for {
|
||||
// select {
|
||||
// case <-pingBefore:
|
||||
// // Wait for event processing to finish.
|
||||
// <-pingAfter
|
||||
// case val <- someOtherChannel:
|
||||
// // do some work with val
|
||||
// case <-pingQuit:
|
||||
// fmt.Printf("xevent loop has quit")
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Note that an unbuffered channel is returned, which implies that any work
|
||||
// done with 'val' will delay further X event processing.
|
||||
//
|
||||
// A complete example using MainPing can be found in the examples directory in
|
||||
// the xgbutil package under the name multiple-source-event-loop.
|
||||
func MainPing(xu *xgbutil.XUtil) (chan struct{}, chan struct{}, chan struct{}) {
|
||||
pingBefore := make(chan struct{}, 0)
|
||||
pingAfter := make(chan struct{}, 0)
|
||||
pingQuit := make(chan struct{}, 0)
|
||||
go func() {
|
||||
mainEventLoop(xu, pingBefore, pingAfter, pingQuit)
|
||||
}()
|
||||
return pingBefore, pingAfter, pingQuit
|
||||
}
|
||||
|
||||
// mainEventLoop runs the main event loop with an optional ping channel.
|
||||
func mainEventLoop(xu *xgbutil.XUtil,
|
||||
pingBefore, pingAfter, pingQuit chan struct{}) {
|
||||
for {
|
||||
if Quitting(xu) {
|
||||
if pingQuit != nil {
|
||||
pingQuit <- struct{}{}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Gobble up as many events as possible (into the queue).
|
||||
// If there are no events, we block.
|
||||
Read(xu, true)
|
||||
|
||||
// Now process every event/error in the queue.
|
||||
processEventQueue(xu, pingBefore, pingAfter)
|
||||
}
|
||||
}
|
||||
|
||||
// processEventQueue processes every item in the event/error queue.
|
||||
func processEventQueue(xu *xgbutil.XUtil, pingBefore, pingAfter chan struct{}) {
|
||||
for !Empty(xu) {
|
||||
if Quitting(xu) {
|
||||
return
|
||||
}
|
||||
|
||||
// We send the ping *before* the next event is dequeued.
|
||||
// This is so the queue doesn't present a misrepresentation of which
|
||||
// events haven't been processed yet.
|
||||
if pingBefore != nil && pingAfter != nil {
|
||||
pingBefore <- struct{}{}
|
||||
}
|
||||
ev, err := Dequeue(xu)
|
||||
|
||||
// If we gobbled up an error, send it to the error event handler
|
||||
// and move on the next event/error.
|
||||
if err != nil {
|
||||
ErrorHandlerGet(xu)(err)
|
||||
if pingBefore != nil && pingAfter != nil {
|
||||
pingAfter <- struct{}{}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// We know there isn't an error. If there isn't an event either,
|
||||
// then there's a bug somewhere.
|
||||
if ev == nil {
|
||||
xgbutil.Logger.Fatal("BUG: Expected an event but got nil.")
|
||||
}
|
||||
|
||||
hooks := getHooks(xu)
|
||||
for _, hook := range hooks {
|
||||
if !hook.Run(xu, ev) {
|
||||
goto END
|
||||
}
|
||||
}
|
||||
|
||||
switch event := ev.(type) {
|
||||
case xproto.KeyPressEvent:
|
||||
e := KeyPressEvent{&event}
|
||||
|
||||
// If we're redirecting key events, this is the place to do it!
|
||||
if wid := RedirectKeyGet(xu); wid > 0 {
|
||||
e.Event = wid
|
||||
}
|
||||
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, KeyPress, e.Event)
|
||||
case xproto.KeyReleaseEvent:
|
||||
e := KeyReleaseEvent{&event}
|
||||
|
||||
// If we're redirecting key events, this is the place to do it!
|
||||
if wid := RedirectKeyGet(xu); wid > 0 {
|
||||
e.Event = wid
|
||||
}
|
||||
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, KeyRelease, e.Event)
|
||||
case xproto.ButtonPressEvent:
|
||||
e := ButtonPressEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, ButtonPress, e.Event)
|
||||
case xproto.ButtonReleaseEvent:
|
||||
e := ButtonReleaseEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, ButtonRelease, e.Event)
|
||||
case xproto.MotionNotifyEvent:
|
||||
e := MotionNotifyEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, MotionNotify, e.Event)
|
||||
case xproto.EnterNotifyEvent:
|
||||
e := EnterNotifyEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, EnterNotify, e.Event)
|
||||
case xproto.LeaveNotifyEvent:
|
||||
e := LeaveNotifyEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, LeaveNotify, e.Event)
|
||||
case xproto.FocusInEvent:
|
||||
e := FocusInEvent{&event}
|
||||
runCallbacks(xu, e, FocusIn, e.Event)
|
||||
case xproto.FocusOutEvent:
|
||||
e := FocusOutEvent{&event}
|
||||
runCallbacks(xu, e, FocusOut, e.Event)
|
||||
case xproto.KeymapNotifyEvent:
|
||||
e := KeymapNotifyEvent{&event}
|
||||
runCallbacks(xu, e, KeymapNotify, NoWindow)
|
||||
case xproto.ExposeEvent:
|
||||
e := ExposeEvent{&event}
|
||||
runCallbacks(xu, e, Expose, e.Window)
|
||||
case xproto.GraphicsExposureEvent:
|
||||
e := GraphicsExposureEvent{&event}
|
||||
runCallbacks(xu, e, GraphicsExposure, xproto.Window(e.Drawable))
|
||||
case xproto.NoExposureEvent:
|
||||
e := NoExposureEvent{&event}
|
||||
runCallbacks(xu, e, NoExposure, xproto.Window(e.Drawable))
|
||||
case xproto.VisibilityNotifyEvent:
|
||||
e := VisibilityNotifyEvent{&event}
|
||||
runCallbacks(xu, e, VisibilityNotify, e.Window)
|
||||
case xproto.CreateNotifyEvent:
|
||||
e := CreateNotifyEvent{&event}
|
||||
runCallbacks(xu, e, CreateNotify, e.Parent)
|
||||
case xproto.DestroyNotifyEvent:
|
||||
e := DestroyNotifyEvent{&event}
|
||||
runCallbacks(xu, e, DestroyNotify, e.Window)
|
||||
case xproto.UnmapNotifyEvent:
|
||||
e := UnmapNotifyEvent{&event}
|
||||
runCallbacks(xu, e, UnmapNotify, e.Window)
|
||||
case xproto.MapNotifyEvent:
|
||||
e := MapNotifyEvent{&event}
|
||||
runCallbacks(xu, e, MapNotify, e.Event)
|
||||
case xproto.MapRequestEvent:
|
||||
e := MapRequestEvent{&event}
|
||||
runCallbacks(xu, e, MapRequest, e.Window)
|
||||
runCallbacks(xu, e, MapRequest, e.Parent)
|
||||
case xproto.ReparentNotifyEvent:
|
||||
e := ReparentNotifyEvent{&event}
|
||||
runCallbacks(xu, e, ReparentNotify, e.Window)
|
||||
case xproto.ConfigureNotifyEvent:
|
||||
e := ConfigureNotifyEvent{&event}
|
||||
runCallbacks(xu, e, ConfigureNotify, e.Window)
|
||||
case xproto.ConfigureRequestEvent:
|
||||
e := ConfigureRequestEvent{&event}
|
||||
runCallbacks(xu, e, ConfigureRequest, e.Window)
|
||||
runCallbacks(xu, e, ConfigureRequest, e.Parent)
|
||||
case xproto.GravityNotifyEvent:
|
||||
e := GravityNotifyEvent{&event}
|
||||
runCallbacks(xu, e, GravityNotify, e.Window)
|
||||
case xproto.ResizeRequestEvent:
|
||||
e := ResizeRequestEvent{&event}
|
||||
runCallbacks(xu, e, ResizeRequest, e.Window)
|
||||
case xproto.CirculateNotifyEvent:
|
||||
e := CirculateNotifyEvent{&event}
|
||||
runCallbacks(xu, e, CirculateNotify, e.Window)
|
||||
case xproto.CirculateRequestEvent:
|
||||
e := CirculateRequestEvent{&event}
|
||||
runCallbacks(xu, e, CirculateRequest, e.Window)
|
||||
case xproto.PropertyNotifyEvent:
|
||||
e := PropertyNotifyEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, PropertyNotify, e.Window)
|
||||
case xproto.SelectionClearEvent:
|
||||
e := SelectionClearEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, SelectionClear, e.Owner)
|
||||
case xproto.SelectionRequestEvent:
|
||||
e := SelectionRequestEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, SelectionRequest, e.Requestor)
|
||||
case xproto.SelectionNotifyEvent:
|
||||
e := SelectionNotifyEvent{&event}
|
||||
xu.TimeSet(e.Time)
|
||||
runCallbacks(xu, e, SelectionNotify, e.Requestor)
|
||||
case xproto.ColormapNotifyEvent:
|
||||
e := ColormapNotifyEvent{&event}
|
||||
runCallbacks(xu, e, ColormapNotify, e.Window)
|
||||
case xproto.ClientMessageEvent:
|
||||
e := ClientMessageEvent{&event}
|
||||
runCallbacks(xu, e, ClientMessage, e.Window)
|
||||
case xproto.MappingNotifyEvent:
|
||||
e := MappingNotifyEvent{&event}
|
||||
runCallbacks(xu, e, MappingNotify, NoWindow)
|
||||
case shape.NotifyEvent:
|
||||
e := ShapeNotifyEvent{&event}
|
||||
runCallbacks(xu, e, ShapeNotify, e.AffectedWindow)
|
||||
default:
|
||||
if event != nil {
|
||||
xgbutil.Logger.Printf("ERROR: UNSUPPORTED EVENT TYPE: %T",
|
||||
event)
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
|
||||
if pingBefore != nil && pingAfter != nil {
|
||||
pingAfter <- struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
336
vendor/github.com/BurntSushi/xgbutil/xevent/types_auto.go
generated
vendored
336
vendor/github.com/BurntSushi/xgbutil/xevent/types_auto.go
generated
vendored
@ -1,336 +0,0 @@
|
||||
package xevent
|
||||
|
||||
/*
|
||||
Defines event types and their associated methods automatically.
|
||||
|
||||
This file is automatically generated using `scripts/write-events evtypes`.
|
||||
|
||||
Edit it at your peril.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/xgb/shape"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
type KeyPressEvent struct {
|
||||
*xproto.KeyPressEvent
|
||||
}
|
||||
|
||||
const KeyPress = xproto.KeyPress
|
||||
|
||||
func (ev KeyPressEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.KeyPressEvent)
|
||||
}
|
||||
|
||||
type KeyReleaseEvent struct {
|
||||
*xproto.KeyReleaseEvent
|
||||
}
|
||||
|
||||
const KeyRelease = xproto.KeyRelease
|
||||
|
||||
func (ev KeyReleaseEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.KeyReleaseEvent)
|
||||
}
|
||||
|
||||
type ButtonPressEvent struct {
|
||||
*xproto.ButtonPressEvent
|
||||
}
|
||||
|
||||
const ButtonPress = xproto.ButtonPress
|
||||
|
||||
func (ev ButtonPressEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ButtonPressEvent)
|
||||
}
|
||||
|
||||
type ButtonReleaseEvent struct {
|
||||
*xproto.ButtonReleaseEvent
|
||||
}
|
||||
|
||||
const ButtonRelease = xproto.ButtonRelease
|
||||
|
||||
func (ev ButtonReleaseEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ButtonReleaseEvent)
|
||||
}
|
||||
|
||||
type MotionNotifyEvent struct {
|
||||
*xproto.MotionNotifyEvent
|
||||
}
|
||||
|
||||
const MotionNotify = xproto.MotionNotify
|
||||
|
||||
func (ev MotionNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.MotionNotifyEvent)
|
||||
}
|
||||
|
||||
type EnterNotifyEvent struct {
|
||||
*xproto.EnterNotifyEvent
|
||||
}
|
||||
|
||||
const EnterNotify = xproto.EnterNotify
|
||||
|
||||
func (ev EnterNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.EnterNotifyEvent)
|
||||
}
|
||||
|
||||
type LeaveNotifyEvent struct {
|
||||
*xproto.LeaveNotifyEvent
|
||||
}
|
||||
|
||||
const LeaveNotify = xproto.LeaveNotify
|
||||
|
||||
func (ev LeaveNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.LeaveNotifyEvent)
|
||||
}
|
||||
|
||||
type FocusInEvent struct {
|
||||
*xproto.FocusInEvent
|
||||
}
|
||||
|
||||
const FocusIn = xproto.FocusIn
|
||||
|
||||
func (ev FocusInEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.FocusInEvent)
|
||||
}
|
||||
|
||||
type FocusOutEvent struct {
|
||||
*xproto.FocusOutEvent
|
||||
}
|
||||
|
||||
const FocusOut = xproto.FocusOut
|
||||
|
||||
func (ev FocusOutEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.FocusOutEvent)
|
||||
}
|
||||
|
||||
type KeymapNotifyEvent struct {
|
||||
*xproto.KeymapNotifyEvent
|
||||
}
|
||||
|
||||
const KeymapNotify = xproto.KeymapNotify
|
||||
|
||||
func (ev KeymapNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.KeymapNotifyEvent)
|
||||
}
|
||||
|
||||
type ExposeEvent struct {
|
||||
*xproto.ExposeEvent
|
||||
}
|
||||
|
||||
const Expose = xproto.Expose
|
||||
|
||||
func (ev ExposeEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ExposeEvent)
|
||||
}
|
||||
|
||||
type GraphicsExposureEvent struct {
|
||||
*xproto.GraphicsExposureEvent
|
||||
}
|
||||
|
||||
const GraphicsExposure = xproto.GraphicsExposure
|
||||
|
||||
func (ev GraphicsExposureEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.GraphicsExposureEvent)
|
||||
}
|
||||
|
||||
type NoExposureEvent struct {
|
||||
*xproto.NoExposureEvent
|
||||
}
|
||||
|
||||
const NoExposure = xproto.NoExposure
|
||||
|
||||
func (ev NoExposureEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.NoExposureEvent)
|
||||
}
|
||||
|
||||
type VisibilityNotifyEvent struct {
|
||||
*xproto.VisibilityNotifyEvent
|
||||
}
|
||||
|
||||
const VisibilityNotify = xproto.VisibilityNotify
|
||||
|
||||
func (ev VisibilityNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.VisibilityNotifyEvent)
|
||||
}
|
||||
|
||||
type CreateNotifyEvent struct {
|
||||
*xproto.CreateNotifyEvent
|
||||
}
|
||||
|
||||
const CreateNotify = xproto.CreateNotify
|
||||
|
||||
func (ev CreateNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.CreateNotifyEvent)
|
||||
}
|
||||
|
||||
type DestroyNotifyEvent struct {
|
||||
*xproto.DestroyNotifyEvent
|
||||
}
|
||||
|
||||
const DestroyNotify = xproto.DestroyNotify
|
||||
|
||||
func (ev DestroyNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.DestroyNotifyEvent)
|
||||
}
|
||||
|
||||
type UnmapNotifyEvent struct {
|
||||
*xproto.UnmapNotifyEvent
|
||||
}
|
||||
|
||||
const UnmapNotify = xproto.UnmapNotify
|
||||
|
||||
func (ev UnmapNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.UnmapNotifyEvent)
|
||||
}
|
||||
|
||||
type MapNotifyEvent struct {
|
||||
*xproto.MapNotifyEvent
|
||||
}
|
||||
|
||||
const MapNotify = xproto.MapNotify
|
||||
|
||||
func (ev MapNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.MapNotifyEvent)
|
||||
}
|
||||
|
||||
type MapRequestEvent struct {
|
||||
*xproto.MapRequestEvent
|
||||
}
|
||||
|
||||
const MapRequest = xproto.MapRequest
|
||||
|
||||
func (ev MapRequestEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.MapRequestEvent)
|
||||
}
|
||||
|
||||
type ReparentNotifyEvent struct {
|
||||
*xproto.ReparentNotifyEvent
|
||||
}
|
||||
|
||||
const ReparentNotify = xproto.ReparentNotify
|
||||
|
||||
func (ev ReparentNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ReparentNotifyEvent)
|
||||
}
|
||||
|
||||
type ConfigureRequestEvent struct {
|
||||
*xproto.ConfigureRequestEvent
|
||||
}
|
||||
|
||||
const ConfigureRequest = xproto.ConfigureRequest
|
||||
|
||||
func (ev ConfigureRequestEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ConfigureRequestEvent)
|
||||
}
|
||||
|
||||
type GravityNotifyEvent struct {
|
||||
*xproto.GravityNotifyEvent
|
||||
}
|
||||
|
||||
const GravityNotify = xproto.GravityNotify
|
||||
|
||||
func (ev GravityNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.GravityNotifyEvent)
|
||||
}
|
||||
|
||||
type ResizeRequestEvent struct {
|
||||
*xproto.ResizeRequestEvent
|
||||
}
|
||||
|
||||
const ResizeRequest = xproto.ResizeRequest
|
||||
|
||||
func (ev ResizeRequestEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ResizeRequestEvent)
|
||||
}
|
||||
|
||||
type CirculateNotifyEvent struct {
|
||||
*xproto.CirculateNotifyEvent
|
||||
}
|
||||
|
||||
const CirculateNotify = xproto.CirculateNotify
|
||||
|
||||
func (ev CirculateNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.CirculateNotifyEvent)
|
||||
}
|
||||
|
||||
type CirculateRequestEvent struct {
|
||||
*xproto.CirculateRequestEvent
|
||||
}
|
||||
|
||||
const CirculateRequest = xproto.CirculateRequest
|
||||
|
||||
func (ev CirculateRequestEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.CirculateRequestEvent)
|
||||
}
|
||||
|
||||
type PropertyNotifyEvent struct {
|
||||
*xproto.PropertyNotifyEvent
|
||||
}
|
||||
|
||||
const PropertyNotify = xproto.PropertyNotify
|
||||
|
||||
func (ev PropertyNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.PropertyNotifyEvent)
|
||||
}
|
||||
|
||||
type SelectionClearEvent struct {
|
||||
*xproto.SelectionClearEvent
|
||||
}
|
||||
|
||||
const SelectionClear = xproto.SelectionClear
|
||||
|
||||
func (ev SelectionClearEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.SelectionClearEvent)
|
||||
}
|
||||
|
||||
type SelectionRequestEvent struct {
|
||||
*xproto.SelectionRequestEvent
|
||||
}
|
||||
|
||||
const SelectionRequest = xproto.SelectionRequest
|
||||
|
||||
func (ev SelectionRequestEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.SelectionRequestEvent)
|
||||
}
|
||||
|
||||
type SelectionNotifyEvent struct {
|
||||
*xproto.SelectionNotifyEvent
|
||||
}
|
||||
|
||||
const SelectionNotify = xproto.SelectionNotify
|
||||
|
||||
func (ev SelectionNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.SelectionNotifyEvent)
|
||||
}
|
||||
|
||||
type ColormapNotifyEvent struct {
|
||||
*xproto.ColormapNotifyEvent
|
||||
}
|
||||
|
||||
const ColormapNotify = xproto.ColormapNotify
|
||||
|
||||
func (ev ColormapNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.ColormapNotifyEvent)
|
||||
}
|
||||
|
||||
type MappingNotifyEvent struct {
|
||||
*xproto.MappingNotifyEvent
|
||||
}
|
||||
|
||||
const MappingNotify = xproto.MappingNotify
|
||||
|
||||
func (ev MappingNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.MappingNotifyEvent)
|
||||
}
|
||||
|
||||
type ShapeNotifyEvent struct {
|
||||
*shape.NotifyEvent
|
||||
}
|
||||
|
||||
const ShapeNotify = shape.Notify
|
||||
|
||||
func (ev ShapeNotifyEvent) String() string {
|
||||
return fmt.Sprintf("%v", ev.NotifyEvent)
|
||||
}
|
90
vendor/github.com/BurntSushi/xgbutil/xevent/types_manual.go
generated
vendored
90
vendor/github.com/BurntSushi/xgbutil/xevent/types_manual.go
generated
vendored
@ -1,90 +0,0 @@
|
||||
package xevent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
// ClientMessageEvent embeds the struct by the same name from the xgb library.
|
||||
type ClientMessageEvent struct {
|
||||
*xproto.ClientMessageEvent
|
||||
}
|
||||
|
||||
const ClientMessage = xproto.ClientMessage
|
||||
|
||||
// NewClientMessage takes all arguments required to build a ClientMessageEvent
|
||||
// struct and hides the messy details.
|
||||
// The variadic parameters coincide with the "data" part of a client message.
|
||||
// The type of the variadic parameters depends upon the value of Format.
|
||||
// If Format is 8, 'data' should have type byte.
|
||||
// If Format is 16, 'data' should have type int16.
|
||||
// If Format is 32, 'data' should have type int.
|
||||
// Any other value of Format returns an error.
|
||||
func NewClientMessage(Format byte, Window xproto.Window, Type xproto.Atom,
|
||||
data ...interface{}) (*ClientMessageEvent, error) {
|
||||
|
||||
// Create the client data list first
|
||||
var clientData xproto.ClientMessageDataUnion
|
||||
|
||||
// Don't support formats 8 or 16 yet. They aren't used in EWMH anyway.
|
||||
switch Format {
|
||||
case 8:
|
||||
buf := make([]byte, 20)
|
||||
for i := 0; i < 20; i++ {
|
||||
if i >= len(data) {
|
||||
break
|
||||
}
|
||||
buf[i] = data[i].(byte)
|
||||
}
|
||||
clientData = xproto.ClientMessageDataUnionData8New(buf)
|
||||
case 16:
|
||||
buf := make([]uint16, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
if i >= len(data) {
|
||||
break
|
||||
}
|
||||
buf[i] = uint16(data[i].(int16))
|
||||
}
|
||||
clientData = xproto.ClientMessageDataUnionData16New(buf)
|
||||
case 32:
|
||||
buf := make([]uint32, 5)
|
||||
for i := 0; i < 5; i++ {
|
||||
if i >= len(data) {
|
||||
break
|
||||
}
|
||||
buf[i] = uint32(data[i].(int))
|
||||
}
|
||||
clientData = xproto.ClientMessageDataUnionData32New(buf)
|
||||
default:
|
||||
return nil, fmt.Errorf("NewClientMessage: Unsupported format '%d'.",
|
||||
Format)
|
||||
}
|
||||
|
||||
return &ClientMessageEvent{&xproto.ClientMessageEvent{
|
||||
Format: Format,
|
||||
Window: Window,
|
||||
Type: Type,
|
||||
Data: clientData,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
// ConfigureNotifyEvent embeds the struct by the same name in XGB.
|
||||
type ConfigureNotifyEvent struct {
|
||||
*xproto.ConfigureNotifyEvent
|
||||
}
|
||||
|
||||
const ConfigureNotify = xproto.ConfigureNotify
|
||||
|
||||
// NewConfigureNotify takes all arguments required to build a
|
||||
// ConfigureNotifyEvent struct and returns a ConfigureNotifyEvent value.
|
||||
func NewConfigureNotify(Event, Window, AboveSibling xproto.Window,
|
||||
X, Y, Width, Height int, BorderWidth uint16,
|
||||
OverrideRedirect bool) *ConfigureNotifyEvent {
|
||||
|
||||
return &ConfigureNotifyEvent{&xproto.ConfigureNotifyEvent{
|
||||
Event: Event, Window: Window, AboveSibling: AboveSibling,
|
||||
X: int16(X), Y: int16(Y), Width: uint16(Width), Height: uint16(Height),
|
||||
BorderWidth: BorderWidth, OverrideRedirect: OverrideRedirect,
|
||||
}}
|
||||
}
|
237
vendor/github.com/BurntSushi/xgbutil/xevent/xevent.go
generated
vendored
237
vendor/github.com/BurntSushi/xgbutil/xevent/xevent.go
generated
vendored
@ -1,237 +0,0 @@
|
||||
package xevent
|
||||
|
||||
import (
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
// Sometimes we need to specify NO WINDOW when a window is typically
|
||||
// expected. (Like connecting to MappingNotify or KeymapNotify events.)
|
||||
// Use this value to do that.
|
||||
var NoWindow xproto.Window = 0
|
||||
|
||||
// IgnoreMods is a list of X modifiers that we don't want interfering
|
||||
// with our mouse or key bindings. In particular, for each mouse or key binding
|
||||
// issued, there is a seperate mouse or key binding made for each of the
|
||||
// modifiers specified.
|
||||
//
|
||||
// You may modify this slice to add (or remove) modifiers, but it should be
|
||||
// done before *any* key or mouse bindings are attached with the keybind and
|
||||
// mousebind packages. It should not be modified afterwards.
|
||||
//
|
||||
// TODO: We're assuming numlock is in the 'mod2' modifier, which is a pretty
|
||||
// common setup, but by no means guaranteed. This should be modified to actually
|
||||
// inspect the modifiers table and look for the special Num_Lock keysym.
|
||||
var IgnoreMods []uint16 = []uint16{
|
||||
0,
|
||||
xproto.ModMaskLock, // Caps lock
|
||||
xproto.ModMask2, // Num lock
|
||||
xproto.ModMaskLock | xproto.ModMask2, // Caps and Num lock
|
||||
}
|
||||
|
||||
// Enqueue queues up an event read from X.
|
||||
// Note that an event read may return an error, in which case, this queue
|
||||
// entry will be an error and not an event.
|
||||
//
|
||||
// ev, err := XUtilValue.Conn().WaitForEvent()
|
||||
// xevent.Enqueue(XUtilValue, ev, err)
|
||||
//
|
||||
// You probably shouldn't have to enqueue events yourself. This is done
|
||||
// automatically if you're using xevent.Main{Ping} and/or xevent.Read.
|
||||
func Enqueue(xu *xgbutil.XUtil, ev xgb.Event, err xgb.Error) {
|
||||
xu.EvqueueLck.Lock()
|
||||
defer xu.EvqueueLck.Unlock()
|
||||
|
||||
xu.Evqueue = append(xu.Evqueue, xgbutil.EventOrError{
|
||||
Event: ev,
|
||||
Err: err,
|
||||
})
|
||||
}
|
||||
|
||||
// Dequeue pops an event/error from the queue and returns it.
|
||||
// The queue item is unwrapped and returned as multiple return values.
|
||||
// Only one of the return values can be nil.
|
||||
func Dequeue(xu *xgbutil.XUtil) (xgb.Event, xgb.Error) {
|
||||
xu.EvqueueLck.Lock()
|
||||
defer xu.EvqueueLck.Unlock()
|
||||
|
||||
everr := xu.Evqueue[0]
|
||||
xu.Evqueue = xu.Evqueue[1:]
|
||||
return everr.Event, everr.Err
|
||||
}
|
||||
|
||||
// DequeueAt removes a particular item from the queue.
|
||||
// This is primarily useful when attempting to compress events.
|
||||
func DequeueAt(xu *xgbutil.XUtil, i int) {
|
||||
xu.EvqueueLck.Lock()
|
||||
defer xu.EvqueueLck.Unlock()
|
||||
|
||||
xu.Evqueue = append(xu.Evqueue[:i], xu.Evqueue[i+1:]...)
|
||||
}
|
||||
|
||||
// Empty returns whether the event queue is empty or not.
|
||||
func Empty(xu *xgbutil.XUtil) bool {
|
||||
xu.EvqueueLck.RLock()
|
||||
defer xu.EvqueueLck.RUnlock()
|
||||
|
||||
return len(xu.Evqueue) == 0
|
||||
}
|
||||
|
||||
// Peek returns a *copy* of the current queue so we can examine it.
|
||||
// This can be useful when trying to determine if a particular kind of
|
||||
// event will be processed in the future.
|
||||
func Peek(xu *xgbutil.XUtil) []xgbutil.EventOrError {
|
||||
xu.EvqueueLck.RLock()
|
||||
defer xu.EvqueueLck.RUnlock()
|
||||
|
||||
cpy := make([]xgbutil.EventOrError, len(xu.Evqueue))
|
||||
copy(cpy, xu.Evqueue)
|
||||
return cpy
|
||||
}
|
||||
|
||||
// ErrorHandlerSet sets the default error handler for errors that come
|
||||
// into the main event loop. (This may be removed in the future in favor
|
||||
// of a particular callback interface like events, but these sorts of errors
|
||||
// aren't handled often in practice, so maybe not.)
|
||||
// This is only called for errors returned from unchecked (asynchronous error
|
||||
// handling) requests.
|
||||
// The default error handler just emits them to stderr.
|
||||
func ErrorHandlerSet(xu *xgbutil.XUtil, fun xgbutil.ErrorHandlerFun) {
|
||||
xu.ErrorHandler = fun
|
||||
}
|
||||
|
||||
// ErrorHandlerGet retrieves the default error handler.
|
||||
func ErrorHandlerGet(xu *xgbutil.XUtil) xgbutil.ErrorHandlerFun {
|
||||
return xu.ErrorHandler
|
||||
}
|
||||
|
||||
type HookFun func(xu *xgbutil.XUtil, event interface{}) bool
|
||||
|
||||
func (callback HookFun) Connect(xu *xgbutil.XUtil) {
|
||||
xu.HooksLck.Lock()
|
||||
defer xu.HooksLck.Unlock()
|
||||
|
||||
// COW
|
||||
newHooks := make([]xgbutil.CallbackHook, len(xu.Hooks))
|
||||
copy(newHooks, xu.Hooks)
|
||||
newHooks = append(newHooks, callback)
|
||||
|
||||
xu.Hooks = newHooks
|
||||
}
|
||||
|
||||
func (callback HookFun) Run(xu *xgbutil.XUtil, event interface{}) bool {
|
||||
return callback(xu, event)
|
||||
}
|
||||
|
||||
func getHooks(xu *xgbutil.XUtil) []xgbutil.CallbackHook {
|
||||
xu.HooksLck.RLock()
|
||||
defer xu.HooksLck.RUnlock()
|
||||
|
||||
return xu.Hooks
|
||||
}
|
||||
|
||||
// RedirectKeyEvents, when set to a window id (greater than 0), will force
|
||||
// *all* Key{Press,Release} to callbacks attached to the specified window.
|
||||
// This is close to emulating a Keyboard grab without the racing.
|
||||
// To stop redirecting key events, use window identifier '0'.
|
||||
func RedirectKeyEvents(xu *xgbutil.XUtil, wid xproto.Window) {
|
||||
xu.KeyRedirect = wid
|
||||
}
|
||||
|
||||
// RedirectKeyGet gets the window that key events are being redirected to.
|
||||
// If 0, then no redirection occurs.
|
||||
func RedirectKeyGet(xu *xgbutil.XUtil) xproto.Window {
|
||||
return xu.KeyRedirect
|
||||
}
|
||||
|
||||
// Quit elegantly exits out of the main event loop.
|
||||
// "Elegantly" in this case means that it finishes processing the current
|
||||
// event, and breaks out of the loop afterwards.
|
||||
// There is no particular reason to use this instead of something like os.Exit
|
||||
// other than you might have code to run after the main event loop exits to
|
||||
// "clean up."
|
||||
func Quit(xu *xgbutil.XUtil) {
|
||||
xu.Quit = true
|
||||
}
|
||||
|
||||
// Quitting returns whether it's time to quit.
|
||||
// This is only used in the main event loop in xevent.
|
||||
func Quitting(xu *xgbutil.XUtil) bool {
|
||||
return xu.Quit
|
||||
}
|
||||
|
||||
// attachCallback associates a (event, window) tuple with an event.
|
||||
// Use copy on write since we run callbacks *a lot* more than attaching them.
|
||||
// (The copy on write only applies to the slice of callbacks rather than
|
||||
// the map itself, since the initial allocation is guaranteed to come before
|
||||
// any use of it.)
|
||||
func attachCallback(xu *xgbutil.XUtil, evtype int, win xproto.Window,
|
||||
fun xgbutil.Callback) {
|
||||
|
||||
xu.CallbacksLck.Lock()
|
||||
defer xu.CallbacksLck.Unlock()
|
||||
|
||||
if _, ok := xu.Callbacks[evtype]; !ok {
|
||||
xu.Callbacks[evtype] = make(map[xproto.Window][]xgbutil.Callback, 20)
|
||||
}
|
||||
if _, ok := xu.Callbacks[evtype][win]; !ok {
|
||||
xu.Callbacks[evtype][win] = make([]xgbutil.Callback, 0)
|
||||
}
|
||||
|
||||
// COW
|
||||
newCallbacks := make([]xgbutil.Callback, len(xu.Callbacks[evtype][win]))
|
||||
copy(newCallbacks, xu.Callbacks[evtype][win])
|
||||
newCallbacks = append(newCallbacks, fun)
|
||||
xu.Callbacks[evtype][win] = newCallbacks
|
||||
}
|
||||
|
||||
// runCallbacks executes every callback corresponding to a
|
||||
// particular event/window tuple.
|
||||
func runCallbacks(xu *xgbutil.XUtil, event interface{}, evtype int,
|
||||
win xproto.Window) {
|
||||
|
||||
// The callback slice for a particular (event type, window) tuple uses
|
||||
// copy on write. So just take a pointer to whatever is there and use that.
|
||||
// We can be sure that the slice won't change from underneathe us.
|
||||
xu.CallbacksLck.RLock()
|
||||
cbs := xu.Callbacks[evtype][win]
|
||||
xu.CallbacksLck.RUnlock()
|
||||
|
||||
for _, cb := range cbs {
|
||||
cb.Run(xu, event)
|
||||
}
|
||||
}
|
||||
|
||||
// Detach removes all callbacks associated with a particular window.
|
||||
// Note that if you're also using the keybind and mousebind packages, a complete
|
||||
// detachment should look like:
|
||||
//
|
||||
// keybind.Detach(XUtilValue, window-id)
|
||||
// mousebind.Detach(XUtilValue, window-id)
|
||||
// xevent.Detach(XUtilValue, window-id)
|
||||
//
|
||||
// If a window is no longer receiving events, these methods should be called.
|
||||
// Otherwise, the memory used to store the handler info for that window will
|
||||
// never be released.
|
||||
func Detach(xu *xgbutil.XUtil, win xproto.Window) {
|
||||
xu.CallbacksLck.Lock()
|
||||
defer xu.CallbacksLck.Unlock()
|
||||
|
||||
for evtype, _ := range xu.Callbacks {
|
||||
delete(xu.Callbacks[evtype], win)
|
||||
}
|
||||
}
|
||||
|
||||
// SendRootEvent takes a type implementing the xgb.Event interface, converts it
|
||||
// to raw X bytes, and sends it to the root window using the SendEvent request.
|
||||
func SendRootEvent(xu *xgbutil.XUtil, ev xgb.Event, evMask uint32) error {
|
||||
return xproto.SendEventChecked(xu.Conn(), false, xu.RootWin(), evMask,
|
||||
string(ev.Bytes())).Check()
|
||||
}
|
||||
|
||||
// ReplayPointer is a quick alias to AllowEvents with 'ReplayPointer' mode.
|
||||
func ReplayPointer(xu *xgbutil.XUtil) {
|
||||
xproto.AllowEvents(xu.Conn(), xproto.AllowReplayPointer, 0)
|
||||
}
|
348
vendor/github.com/BurntSushi/xgbutil/xgbutil.go
generated
vendored
348
vendor/github.com/BurntSushi/xgbutil/xgbutil.go
generated
vendored
@ -1,348 +0,0 @@
|
||||
package xgbutil
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xinerama"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
)
|
||||
|
||||
// Logger is used through xgbutil when messages need to be emitted to stderr.
|
||||
var Logger = log.New(os.Stderr, "[xgbutil] ", log.Lshortfile)
|
||||
|
||||
// The current maximum request size. I think we can expand this with
|
||||
// BigReq, but it probably isn't worth it at the moment.
|
||||
const MaxReqSize = (1 << 16) * 4
|
||||
|
||||
// An XUtil represents the state of xgbutil. It keeps track of the current
|
||||
// X connection, the root window, event callbacks, key/mouse bindings, etc.
|
||||
// Regrettably, many of the members are exported, even though they should not
|
||||
// be used directly by the user. They are exported for use in sub-packages.
|
||||
// (Namely, xevent, keybind and mousebind.) In fact, there should *never*
|
||||
// be a reason to access any members of an XUtil value directly. Any
|
||||
// interaction with an XUtil value should be through its methods.
|
||||
type XUtil struct {
|
||||
// conn is the XGB connection object used to issue protocol requests.
|
||||
conn *xgb.Conn
|
||||
|
||||
// Quit can be set to true, and the main event loop will finish processing
|
||||
// the current event, and gracefully quit afterwards.
|
||||
// This is exported for use in the xevent package. Please us xevent.Quit
|
||||
// to set this value.
|
||||
Quit bool // when true, the main event loop will stop gracefully
|
||||
|
||||
// setup contains all the setup information retrieved at connection time.
|
||||
setup *xproto.SetupInfo
|
||||
|
||||
// screen is a simple alias to the default screen info.
|
||||
screen *xproto.ScreenInfo
|
||||
|
||||
// root is an alias to the default root window.
|
||||
root xproto.Window
|
||||
|
||||
// Atoms is a cache of atom names to resource identifiers. This minimizes
|
||||
// round trips to the X server, since atom identifiers never change.
|
||||
// It is exported for use in the xprop package. It should not be used.
|
||||
Atoms map[string]xproto.Atom
|
||||
AtomsLck *sync.RWMutex
|
||||
|
||||
// AtomNames is a cache just like 'atoms', but in the reverse direction.
|
||||
// It is exported for use in the xprop package. It should not be used.
|
||||
AtomNames map[xproto.Atom]string
|
||||
AtomNamesLck *sync.RWMutex
|
||||
|
||||
// Evqueue is the queue that stores the results of xgb.WaitForEvent.
|
||||
// Namely, each value is either an Event *or* an Error.
|
||||
// It is exported for use in the xevent package. Do not use it.
|
||||
// If you need to interact with the event queue, please use the functions
|
||||
// available in the xevent package: Dequeue, DequeueAt, QueueEmpty
|
||||
// and QueuePeek.
|
||||
Evqueue []EventOrError
|
||||
EvqueueLck *sync.RWMutex
|
||||
|
||||
// Callbacks is a map of event numbers to a map of window identifiers
|
||||
// to callback functions.
|
||||
// This is the data structure that stores all callback functions, where
|
||||
// a callback function is always attached to a (event, window) tuple.
|
||||
// It is exported for use in the xevent package. Do not use it.
|
||||
Callbacks map[int]map[xproto.Window][]Callback
|
||||
CallbacksLck *sync.RWMutex
|
||||
|
||||
// Hooks are called by the XEvent main loop before processing the event
|
||||
// itself. These are meant for instances when it's not possible / easy
|
||||
// to use the normal Hook system. You should not modify this yourself.
|
||||
Hooks []CallbackHook
|
||||
HooksLck *sync.RWMutex
|
||||
|
||||
// eventTime is the last time recorded by an event. It is automatically
|
||||
// updated if xgbutil's main event loop is used.
|
||||
eventTime xproto.Timestamp
|
||||
|
||||
// Keymap corresponds to xgbutil's current conception of the keyboard
|
||||
// mapping. It is automatically kept up-to-date if xgbutil's event loop
|
||||
// is used.
|
||||
// It is exported for use in the keybind package. It should not be
|
||||
// accessed directly. Instead, use keybind.KeyMapGet.
|
||||
Keymap *KeyboardMapping
|
||||
|
||||
// Modmap corresponds to xgbutil's current conception of the modifier key
|
||||
// mapping. It is automatically kept up-to-date if xgbutil's event loop
|
||||
// is used.
|
||||
// It is exported for use in the keybind package. It should not be
|
||||
// accessed directly. Instead, use keybind.ModMapGet.
|
||||
Modmap *ModifierMapping
|
||||
|
||||
// KeyRedirect corresponds to a window identifier that, when set,
|
||||
// automatically receives *all* keyboard events. This is a sort-of
|
||||
// synthetic grab and is helpful in avoiding race conditions.
|
||||
// It is exported for use in the xevent and keybind packages. Do not use
|
||||
// it directly. To redirect key events, please use xevent.RedirectKeyEvents.
|
||||
KeyRedirect xproto.Window
|
||||
|
||||
// Keybinds is the data structure storing all callbacks for key bindings.
|
||||
// This is extremely similar to the general notion of event callbacks,
|
||||
// but adds extra support to make handling key bindings easier. (Like
|
||||
// specifying human readable key sequences to bind to.)
|
||||
// KeyBindKey is a struct representing the 4-tuple
|
||||
// (event-type, window-id, modifiers, keycode).
|
||||
// It is exported for use in the keybind package. Do not access it directly.
|
||||
Keybinds map[KeyKey][]CallbackKey
|
||||
KeybindsLck *sync.RWMutex
|
||||
|
||||
// Keygrabs is a frequency count of the number of callbacks associated
|
||||
// with a particular KeyBindKey. This is necessary because we can only
|
||||
// grab a particular key *once*, but we may want to attach several callbacks
|
||||
// to a single keypress.
|
||||
// It is exported for use in the keybind package. Do not access it directly.
|
||||
Keygrabs map[KeyKey]int
|
||||
|
||||
// Keystrings is a list of all key strings used to connect keybindings.
|
||||
// They are used to rebuild key grabs when the keyboard mapping is updated.
|
||||
// It is exported for use in the keybind package. Do not access it directly.
|
||||
Keystrings []KeyString
|
||||
|
||||
// Mousebinds is the data structure storing all callbacks for mouse
|
||||
// bindings.This is extremely similar to the general notion of event
|
||||
// callbacks,but adds extra support to make handling mouse bindings easier.
|
||||
// (Like specifying human readable mouse sequences to bind to.)
|
||||
// MouseBindKey is a struct representing the 4-tuple
|
||||
// (event-type, window-id, modifiers, button).
|
||||
// It is exported for use in the mousebind package. Do not use it.
|
||||
Mousebinds map[MouseKey][]CallbackMouse
|
||||
MousebindsLck *sync.RWMutex
|
||||
|
||||
// Mousegrabs is a frequency count of the number of callbacks associated
|
||||
// with a particular MouseBindKey. This is necessary because we can only
|
||||
// grab a particular mouse button *once*, but we may want to attach
|
||||
// several callbacks to a single button press.
|
||||
// It is exported for use in the mousebind package. Do not use it.
|
||||
Mousegrabs map[MouseKey]int
|
||||
|
||||
// InMouseDrag is true if a drag is currently in progress.
|
||||
// It is exported for use in the mousebind package. Do not use it.
|
||||
InMouseDrag bool
|
||||
|
||||
// MouseDragStep is the function executed for each step (i.e., pointer
|
||||
// movement) in the current mouse drag. Note that this is nil when a drag
|
||||
// is not in progress.
|
||||
// It is exported for use in the mousebind package. Do not use it.
|
||||
MouseDragStepFun MouseDragFun
|
||||
|
||||
// MouseDragEnd is the function executed at the end of the current
|
||||
// mouse drag. This is nil when a drag is not in progress.
|
||||
// It is exported for use in the mousebind package. Do not use it.
|
||||
MouseDragEndFun MouseDragFun
|
||||
|
||||
// gc is a general purpose graphics context; used to paint images.
|
||||
// Since we don't do any real X drawing, we don't really care about the
|
||||
// particulars of our graphics context.
|
||||
gc xproto.Gcontext
|
||||
|
||||
// dummy is a dummy window used for mouse/key GRABs.
|
||||
// Basically, whenever a grab is instituted, mouse and key events are
|
||||
// redirected to the dummy the window.
|
||||
dummy xproto.Window
|
||||
|
||||
// ErrorHandler is the function that handles errors *in the event loop*.
|
||||
// By default, it simply emits them to stderr.
|
||||
// It is exported for use in the xevent package. To set the default error
|
||||
// handler, please use xevent.ErrorHandlerSet.
|
||||
ErrorHandler ErrorHandlerFun
|
||||
}
|
||||
|
||||
// NewConn connects to the X server using the DISPLAY environment variable
|
||||
// and creates a new XUtil. Most environments have the DISPLAY environment
|
||||
// variable set, so this is probably what you want to use to connect to X.
|
||||
func NewConn() (*XUtil, error) {
|
||||
return NewConnDisplay("")
|
||||
}
|
||||
|
||||
// NewConnDisplay connects to the X server and creates a new XUtil.
|
||||
// If 'display' is empty, the DISPLAY environment variable is used. Otherwise
|
||||
// there are several different display formats supported:
|
||||
//
|
||||
// NewConn(":1") -> net.Dial("unix", "", "/tmp/.X11-unix/X1")
|
||||
// NewConn("/tmp/launch-12/:0") -> net.Dial("unix", "", "/tmp/launch-12/:0")
|
||||
// NewConn("hostname:2.1") -> net.Dial("tcp", "", "hostname:6002")
|
||||
// NewConn("tcp/hostname:1.0") -> net.Dial("tcp", "", "hostname:6001")
|
||||
func NewConnDisplay(display string) (*XUtil, error) {
|
||||
c, err := xgb.NewConnDisplay(display)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewConnXgb(c)
|
||||
|
||||
}
|
||||
|
||||
// NewConnXgb use the specific xgb.Conn to create a new XUtil.
|
||||
//
|
||||
// NewConn, NewConnDisplay are wrapper of this function.
|
||||
func NewConnXgb(c *xgb.Conn) (*XUtil, error) {
|
||||
setup := xproto.Setup(c)
|
||||
screen := setup.DefaultScreen(c)
|
||||
|
||||
// Initialize our central struct that stores everything.
|
||||
xu := &XUtil{
|
||||
conn: c,
|
||||
Quit: false,
|
||||
Evqueue: make([]EventOrError, 0, 1000),
|
||||
EvqueueLck: &sync.RWMutex{},
|
||||
setup: setup,
|
||||
screen: screen,
|
||||
root: screen.Root,
|
||||
eventTime: xproto.Timestamp(0), // last event time
|
||||
Atoms: make(map[string]xproto.Atom, 50),
|
||||
AtomsLck: &sync.RWMutex{},
|
||||
AtomNames: make(map[xproto.Atom]string, 50),
|
||||
AtomNamesLck: &sync.RWMutex{},
|
||||
Callbacks: make(map[int]map[xproto.Window][]Callback, 33),
|
||||
CallbacksLck: &sync.RWMutex{},
|
||||
Hooks: make([]CallbackHook, 0),
|
||||
HooksLck: &sync.RWMutex{},
|
||||
Keymap: nil, // we don't have anything yet
|
||||
Modmap: nil,
|
||||
KeyRedirect: 0,
|
||||
Keybinds: make(map[KeyKey][]CallbackKey, 10),
|
||||
KeybindsLck: &sync.RWMutex{},
|
||||
Keygrabs: make(map[KeyKey]int, 10),
|
||||
Keystrings: make([]KeyString, 0, 10),
|
||||
Mousebinds: make(map[MouseKey][]CallbackMouse, 10),
|
||||
MousebindsLck: &sync.RWMutex{},
|
||||
Mousegrabs: make(map[MouseKey]int, 10),
|
||||
InMouseDrag: false,
|
||||
MouseDragStepFun: nil,
|
||||
MouseDragEndFun: nil,
|
||||
ErrorHandler: func(err xgb.Error) { Logger.Println(err) },
|
||||
}
|
||||
|
||||
var err error = nil
|
||||
// Create a general purpose graphics context
|
||||
xu.gc, err = xproto.NewGcontextId(xu.conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
xproto.CreateGC(xu.conn, xu.gc, xproto.Drawable(xu.root),
|
||||
xproto.GcForeground, []uint32{xu.screen.WhitePixel})
|
||||
|
||||
// Create a dummy window
|
||||
xu.dummy, err = xproto.NewWindowId(xu.conn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
xproto.CreateWindow(xu.conn, xu.Screen().RootDepth, xu.dummy, xu.RootWin(),
|
||||
-1000, -1000, 1, 1, 0,
|
||||
xproto.WindowClassInputOutput, xu.Screen().RootVisual,
|
||||
xproto.CwEventMask|xproto.CwOverrideRedirect,
|
||||
[]uint32{1, xproto.EventMaskPropertyChange})
|
||||
xproto.MapWindow(xu.conn, xu.dummy)
|
||||
|
||||
// Register the Xinerama extension... because it doesn't cost much.
|
||||
err = xinerama.Init(xu.conn)
|
||||
|
||||
// If we can't register Xinerama, that's okay. Output something
|
||||
// and move on.
|
||||
if err != nil {
|
||||
Logger.Printf("WARNING: %s\n", err)
|
||||
Logger.Printf("MESSAGE: The 'xinerama' package cannot be used " +
|
||||
"because the XINERAMA extension could not be loaded.")
|
||||
}
|
||||
|
||||
return xu, nil
|
||||
}
|
||||
|
||||
// Conn returns the xgb connection object.
|
||||
func (xu *XUtil) Conn() *xgb.Conn {
|
||||
return xu.conn
|
||||
}
|
||||
|
||||
// ExtInitialized returns true if an extension has been initialized.
|
||||
// This is useful for determining whether an extension is available or not.
|
||||
func (xu *XUtil) ExtInitialized(extName string) bool {
|
||||
_, ok := xu.Conn().Extensions[extName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Sync forces XGB to catch up with all events/requests and synchronize.
|
||||
// This is done by issuing a benign round trip request to X.
|
||||
func (xu *XUtil) Sync() {
|
||||
xproto.GetInputFocus(xu.Conn()).Reply()
|
||||
}
|
||||
|
||||
// Setup returns the setup information retrieved during connection time.
|
||||
func (xu *XUtil) Setup() *xproto.SetupInfo {
|
||||
return xu.setup
|
||||
}
|
||||
|
||||
// Screen returns the default screen
|
||||
func (xu *XUtil) Screen() *xproto.ScreenInfo {
|
||||
return xu.screen
|
||||
}
|
||||
|
||||
// RootWin returns the current root window.
|
||||
func (xu *XUtil) RootWin() xproto.Window {
|
||||
return xu.root
|
||||
}
|
||||
|
||||
// RootWinSet will change the current root window to the one provided.
|
||||
// N.B. This probably shouldn't be used unless you're desperately trying
|
||||
// to support multiple X screens. (This is *not* the same as Xinerama/RandR or
|
||||
// TwinView. All of those have a single root window.)
|
||||
func (xu *XUtil) RootWinSet(root xproto.Window) {
|
||||
xu.root = root
|
||||
}
|
||||
|
||||
// TimeGet gets the most recent time seen by an event.
|
||||
func (xu *XUtil) TimeGet() xproto.Timestamp {
|
||||
return xu.eventTime
|
||||
}
|
||||
|
||||
// TimeSet sets the most recent time seen by an event.
|
||||
func (xu *XUtil) TimeSet(t xproto.Timestamp) {
|
||||
xu.eventTime = t
|
||||
}
|
||||
|
||||
// GC gets a general purpose graphics context that is typically used to simply
|
||||
// paint images.
|
||||
func (xu *XUtil) GC() xproto.Gcontext {
|
||||
return xu.gc
|
||||
}
|
||||
|
||||
// Dummy gets the id of the dummy window.
|
||||
func (xu *XUtil) Dummy() xproto.Window {
|
||||
return xu.dummy
|
||||
}
|
||||
|
||||
// Grabs the server. Everything becomes synchronous.
|
||||
func (xu *XUtil) Grab() {
|
||||
xproto.GrabServer(xu.Conn())
|
||||
}
|
||||
|
||||
// Ungrabs the server.
|
||||
func (xu *XUtil) Ungrab() {
|
||||
xproto.UngrabServer(xu.Conn())
|
||||
}
|
103
vendor/github.com/BurntSushi/xgbutil/xprop/atom.go
generated
vendored
103
vendor/github.com/BurntSushi/xgbutil/xprop/atom.go
generated
vendored
@ -1,103 +0,0 @@
|
||||
package xprop
|
||||
|
||||
/*
|
||||
xprop/atom.go contains functions related to interning atoms and retrieving
|
||||
atom names from an atom identifier.
|
||||
|
||||
It also manages an atom cache so that once an atom is interned from the X
|
||||
server, all future atom interns use that value. (So that one and only one
|
||||
request is sent for interning each atom.)
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
// Atm is a short alias for Atom in the common case of interning an atom.
|
||||
// Namely, interning the atom always succeeds. (If the atom does not already
|
||||
// exist, a new one is created.)
|
||||
func Atm(xu *xgbutil.XUtil, name string) (xproto.Atom, error) {
|
||||
aid, err := Atom(xu, name, false)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if aid == 0 {
|
||||
return 0, fmt.Errorf("Atm: '%s' returned an identifier of 0.", name)
|
||||
}
|
||||
|
||||
return aid, err
|
||||
}
|
||||
|
||||
// Atom interns an atom and panics if there is any error.
|
||||
func Atom(xu *xgbutil.XUtil, name string,
|
||||
onlyIfExists bool) (xproto.Atom, error) {
|
||||
|
||||
// Check the cache first
|
||||
if aid, ok := atomGet(xu, name); ok {
|
||||
return aid, nil
|
||||
}
|
||||
|
||||
reply, err := xproto.InternAtom(xu.Conn(), onlyIfExists,
|
||||
uint16(len(name)), name).Reply()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Atom: Error interning atom '%s': %s", name, err)
|
||||
}
|
||||
|
||||
// If we're here, it means we didn't have this atom cached. So cache it!
|
||||
cacheAtom(xu, name, reply.Atom)
|
||||
|
||||
return reply.Atom, nil
|
||||
}
|
||||
|
||||
// AtomName fetches a string representation of an ATOM given its integer id.
|
||||
func AtomName(xu *xgbutil.XUtil, aid xproto.Atom) (string, error) {
|
||||
// Check the cache first
|
||||
if atomName, ok := atomNameGet(xu, aid); ok {
|
||||
return string(atomName), nil
|
||||
}
|
||||
|
||||
reply, err := xproto.GetAtomName(xu.Conn(), aid).Reply()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("AtomName: Error fetching name for ATOM "+
|
||||
"id '%d': %s", aid, err)
|
||||
}
|
||||
|
||||
// If we're here, it means we didn't have ths ATOM id cached. So cache it.
|
||||
atomName := string(reply.Name)
|
||||
cacheAtom(xu, atomName, aid)
|
||||
|
||||
return atomName, nil
|
||||
}
|
||||
|
||||
// atomGet retrieves an atom identifier from a cache if it exists.
|
||||
func atomGet(xu *xgbutil.XUtil, name string) (xproto.Atom, bool) {
|
||||
xu.AtomsLck.RLock()
|
||||
defer xu.AtomsLck.RUnlock()
|
||||
|
||||
aid, ok := xu.Atoms[name]
|
||||
return aid, ok
|
||||
}
|
||||
|
||||
// atomNameGet retrieves an atom name from a cache if it exists.
|
||||
func atomNameGet(xu *xgbutil.XUtil, aid xproto.Atom) (string, bool) {
|
||||
xu.AtomNamesLck.RLock()
|
||||
defer xu.AtomNamesLck.RUnlock()
|
||||
|
||||
name, ok := xu.AtomNames[aid]
|
||||
return name, ok
|
||||
}
|
||||
|
||||
// cacheAtom puts an atom into the cache.
|
||||
func cacheAtom(xu *xgbutil.XUtil, name string, aid xproto.Atom) {
|
||||
xu.AtomsLck.Lock()
|
||||
xu.AtomNamesLck.Lock()
|
||||
defer xu.AtomsLck.Unlock()
|
||||
defer xu.AtomNamesLck.Unlock()
|
||||
|
||||
xu.Atoms[name] = aid
|
||||
xu.AtomNames[aid] = name
|
||||
}
|
40
vendor/github.com/BurntSushi/xgbutil/xprop/doc.go
generated
vendored
40
vendor/github.com/BurntSushi/xgbutil/xprop/doc.go
generated
vendored
@ -1,40 +0,0 @@
|
||||
/*
|
||||
Package xprop provides a cache for interning atoms and helper functions for
|
||||
dealing with GetProperty and ChangeProperty X requests.
|
||||
|
||||
Atoms
|
||||
|
||||
Atoms in X are interned, meaning that strings are assigned unique integer
|
||||
identifiers. This minimizes the amount of data transmitted over an X connection.
|
||||
|
||||
Once atoms have been interned, they are never changed while the X server is
|
||||
running. xgbutil takes advantage of this invariant and will only issue an
|
||||
intern atom request once and cache the result.
|
||||
|
||||
To use the xprop package to intern an atom, use Atom:
|
||||
|
||||
atom, err := xprop.Atom(XUtilValue, "THE_ATOM_NAME", false)
|
||||
if err == nil {
|
||||
println("The atom number: ", atom.Atom)
|
||||
}
|
||||
|
||||
The 'false' parameter corresponds to the 'only_if_exists' parameter of the
|
||||
X InternAtom request. When it's false, the atom being interned always returns
|
||||
a non-zero atom number---even if the string being interned hasn't been interned
|
||||
before. If 'only_if_exists' is true, the atom being interned will return a 0
|
||||
atom number if it hasn't already been interned.
|
||||
|
||||
The typical case is to set 'only_if_exists' to false. To this end, xprop.Atm is
|
||||
an alias that always sets this value to false.
|
||||
|
||||
The reverse can also be done: getting an atom string if you have an atom
|
||||
number. This can be done with the xprop.AtomName function.
|
||||
|
||||
Properties
|
||||
|
||||
The other facility of xprop is to help with the use of GetProperty and
|
||||
ChangeProperty. Please see the source code of the ewmh package for plenty of
|
||||
examples.
|
||||
|
||||
*/
|
||||
package xprop
|
270
vendor/github.com/BurntSushi/xgbutil/xprop/xprop.go
generated
vendored
270
vendor/github.com/BurntSushi/xgbutil/xprop/xprop.go
generated
vendored
@ -1,270 +0,0 @@
|
||||
package xprop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/xgb"
|
||||
"github.com/BurntSushi/xgb/xproto"
|
||||
|
||||
"github.com/BurntSushi/xgbutil"
|
||||
)
|
||||
|
||||
// GetProperty abstracts the messiness of calling xgb.GetProperty.
|
||||
func GetProperty(xu *xgbutil.XUtil, win xproto.Window, atom string) (
|
||||
*xproto.GetPropertyReply, error) {
|
||||
|
||||
atomId, err := Atm(xu, atom)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reply, err := xproto.GetProperty(xu.Conn(), false, win, atomId,
|
||||
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetProperty: Error retrieving property '%s' "+
|
||||
"on window %x: %s", atom, win, err)
|
||||
}
|
||||
|
||||
if reply.Format == 0 {
|
||||
return nil, fmt.Errorf("GetProperty: No such property '%s' on "+
|
||||
"window %x.", atom, win)
|
||||
}
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
// ChangeProperty abstracts the semi-nastiness of xgb.ChangeProperty.
|
||||
func ChangeProp(xu *xgbutil.XUtil, win xproto.Window, format byte, prop string,
|
||||
typ string, data []byte) error {
|
||||
|
||||
propAtom, err := Atm(xu, prop)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
typAtom, err := Atm(xu, typ)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return xproto.ChangePropertyChecked(xu.Conn(), xproto.PropModeReplace, win,
|
||||
propAtom, typAtom, format,
|
||||
uint32(len(data)/(int(format)/8)), data).Check()
|
||||
}
|
||||
|
||||
// ChangeProperty32 makes changing 32 bit formatted properties easier
|
||||
// by constructing the raw X data for you.
|
||||
func ChangeProp32(xu *xgbutil.XUtil, win xproto.Window, prop string, typ string,
|
||||
data ...uint) error {
|
||||
|
||||
buf := make([]byte, len(data)*4)
|
||||
for i, datum := range data {
|
||||
xgb.Put32(buf[(i*4):], uint32(datum))
|
||||
}
|
||||
|
||||
return ChangeProp(xu, win, 32, prop, typ, buf)
|
||||
}
|
||||
|
||||
// WindowToUint is a covenience function for converting []xproto.Window
|
||||
// to []uint.
|
||||
func WindowToInt(ids []xproto.Window) []uint {
|
||||
ids32 := make([]uint, len(ids))
|
||||
for i, v := range ids {
|
||||
ids32[i] = uint(v)
|
||||
}
|
||||
return ids32
|
||||
}
|
||||
|
||||
// AtomToInt is a covenience function for converting []xproto.Atom
|
||||
// to []uint.
|
||||
func AtomToUint(ids []xproto.Atom) []uint {
|
||||
ids32 := make([]uint, len(ids))
|
||||
for i, v := range ids {
|
||||
ids32[i] = uint(v)
|
||||
}
|
||||
return ids32
|
||||
}
|
||||
|
||||
// StrToAtoms is a convenience function for converting
|
||||
// []string to []uint32 atoms.
|
||||
// NOTE: If an atom name in the list doesn't exist, it will be created.
|
||||
func StrToAtoms(xu *xgbutil.XUtil, atomNames []string) ([]uint, error) {
|
||||
var err error
|
||||
atoms := make([]uint, len(atomNames))
|
||||
for i, atomName := range atomNames {
|
||||
a, err := Atom(xu, atomName, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
atoms[i] = uint(a)
|
||||
}
|
||||
return atoms, err
|
||||
}
|
||||
|
||||
// PropValAtom transforms a GetPropertyReply struct into an ATOM name.
|
||||
// The property reply must be in 32 bit format.
|
||||
func PropValAtom(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply,
|
||||
err error) (string, error) {
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return "", fmt.Errorf("PropValAtom: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
|
||||
return AtomName(xu, xproto.Atom(xgb.Get32(reply.Value)))
|
||||
}
|
||||
|
||||
// PropValAtoms is the same as PropValAtom, except that it returns a slice
|
||||
// of atom names. Also must be 32 bit format.
|
||||
// This is a method of an XUtil struct, unlike the other 'PropVal...' functions.
|
||||
func PropValAtoms(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply,
|
||||
err error) ([]string, error) {
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return nil, fmt.Errorf("PropValAtoms: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
|
||||
ids := make([]string, reply.ValueLen)
|
||||
vals := reply.Value
|
||||
for i := 0; len(vals) >= 4; i++ {
|
||||
ids[i], err = AtomName(xu, xproto.Atom(xgb.Get32(vals)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vals = vals[4:]
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// PropValWindow transforms a GetPropertyReply struct into an X resource
|
||||
// window identifier.
|
||||
// The property reply must be in 32 bit format.
|
||||
func PropValWindow(reply *xproto.GetPropertyReply,
|
||||
err error) (xproto.Window, error) {
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return 0, fmt.Errorf("PropValId: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
return xproto.Window(xgb.Get32(reply.Value)), nil
|
||||
}
|
||||
|
||||
// PropValWindows is the same as PropValWindow, except that it returns a slice
|
||||
// of identifiers. Also must be 32 bit format.
|
||||
func PropValWindows(reply *xproto.GetPropertyReply,
|
||||
err error) ([]xproto.Window, error) {
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
|
||||
ids := make([]xproto.Window, reply.ValueLen)
|
||||
vals := reply.Value
|
||||
for i := 0; len(vals) >= 4; i++ {
|
||||
ids[i] = xproto.Window(xgb.Get32(vals))
|
||||
vals = vals[4:]
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// PropValNum transforms a GetPropertyReply struct into an unsigned
|
||||
// integer. Useful when the property value is a single integer.
|
||||
func PropValNum(reply *xproto.GetPropertyReply, err error) (uint, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
return uint(xgb.Get32(reply.Value)), nil
|
||||
}
|
||||
|
||||
// PropValNums is the same as PropValNum, except that it returns a slice
|
||||
// of integers. Also must be 32 bit format.
|
||||
func PropValNums(reply *xproto.GetPropertyReply, err error) ([]uint, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
|
||||
nums := make([]uint, reply.ValueLen)
|
||||
vals := reply.Value
|
||||
for i := 0; len(vals) >= 4; i++ {
|
||||
nums[i] = uint(xgb.Get32(vals))
|
||||
vals = vals[4:]
|
||||
}
|
||||
return nums, nil
|
||||
}
|
||||
|
||||
// PropValNum64 transforms a GetPropertyReply struct into a 64 bit
|
||||
// integer. Useful when the property value is a single integer.
|
||||
func PropValNum64(reply *xproto.GetPropertyReply, err error) (int64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if reply.Format != 32 {
|
||||
return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
return int64(xgb.Get32(reply.Value)), nil
|
||||
}
|
||||
|
||||
// PropValStr transforms a GetPropertyReply struct into a string.
|
||||
// Useful when the property value is a null terminated string represented
|
||||
// by integers. Also must be 8 bit format.
|
||||
func PropValStr(reply *xproto.GetPropertyReply, err error) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if reply.Format != 8 {
|
||||
return "", fmt.Errorf("PropValStr: Expected format 8 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
return string(reply.Value), nil
|
||||
}
|
||||
|
||||
// PropValStrs is the same as PropValStr, except that it returns a slice
|
||||
// of strings. The raw byte string is a sequence of null terminated strings,
|
||||
// which is translated into a slice of strings.
|
||||
func PropValStrs(reply *xproto.GetPropertyReply, err error) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.Format != 8 {
|
||||
return nil, fmt.Errorf("PropValStrs: Expected format 8 but got %d",
|
||||
reply.Format)
|
||||
}
|
||||
|
||||
var strs []string
|
||||
sstart := 0
|
||||
for i, c := range reply.Value {
|
||||
if c == 0 {
|
||||
strs = append(strs, string(reply.Value[sstart:i]))
|
||||
sstart = i + 1
|
||||
}
|
||||
}
|
||||
if sstart < int(reply.ValueLen) {
|
||||
strs = append(strs, string(reply.Value[sstart:]))
|
||||
}
|
||||
return strs, nil
|
||||
}
|
20
vendor/github.com/StackExchange/wmi/LICENSE
generated
vendored
20
vendor/github.com/StackExchange/wmi/LICENSE
generated
vendored
@ -1,20 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Stack Exchange
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
6
vendor/github.com/StackExchange/wmi/README.md
generated
vendored
6
vendor/github.com/StackExchange/wmi/README.md
generated
vendored
@ -1,6 +0,0 @@
|
||||
wmi
|
||||
===
|
||||
|
||||
Package wmi provides a WQL interface to Windows WMI.
|
||||
|
||||
Note: It interfaces with WMI on the local machine, therefore it only runs on Windows.
|
260
vendor/github.com/StackExchange/wmi/swbemservices.go
generated
vendored
260
vendor/github.com/StackExchange/wmi/swbemservices.go
generated
vendored
@ -1,260 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package wmi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
)
|
||||
|
||||
// SWbemServices is used to access wmi. See https://msdn.microsoft.com/en-us/library/aa393719(v=vs.85).aspx
|
||||
type SWbemServices struct {
|
||||
//TODO: track namespace. Not sure if we can re connect to a different namespace using the same instance
|
||||
cWMIClient *Client //This could also be an embedded struct, but then we would need to branch on Client vs SWbemServices in the Query method
|
||||
sWbemLocatorIUnknown *ole.IUnknown
|
||||
sWbemLocatorIDispatch *ole.IDispatch
|
||||
queries chan *queryRequest
|
||||
closeError chan error
|
||||
lQueryorClose sync.Mutex
|
||||
}
|
||||
|
||||
type queryRequest struct {
|
||||
query string
|
||||
dst interface{}
|
||||
args []interface{}
|
||||
finished chan error
|
||||
}
|
||||
|
||||
// InitializeSWbemServices will return a new SWbemServices object that can be used to query WMI
|
||||
func InitializeSWbemServices(c *Client, connectServerArgs ...interface{}) (*SWbemServices, error) {
|
||||
//fmt.Println("InitializeSWbemServices: Starting")
|
||||
//TODO: implement connectServerArgs as optional argument for init with connectServer call
|
||||
s := new(SWbemServices)
|
||||
s.cWMIClient = c
|
||||
s.queries = make(chan *queryRequest)
|
||||
initError := make(chan error)
|
||||
go s.process(initError)
|
||||
|
||||
err, ok := <-initError
|
||||
if ok {
|
||||
return nil, err //Send error to caller
|
||||
}
|
||||
//fmt.Println("InitializeSWbemServices: Finished")
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Close will clear and release all of the SWbemServices resources
|
||||
func (s *SWbemServices) Close() error {
|
||||
s.lQueryorClose.Lock()
|
||||
if s == nil || s.sWbemLocatorIDispatch == nil {
|
||||
s.lQueryorClose.Unlock()
|
||||
return fmt.Errorf("SWbemServices is not Initialized")
|
||||
}
|
||||
if s.queries == nil {
|
||||
s.lQueryorClose.Unlock()
|
||||
return fmt.Errorf("SWbemServices has been closed")
|
||||
}
|
||||
//fmt.Println("Close: sending close request")
|
||||
var result error
|
||||
ce := make(chan error)
|
||||
s.closeError = ce //Race condition if multiple callers to close. May need to lock here
|
||||
close(s.queries) //Tell background to shut things down
|
||||
s.lQueryorClose.Unlock()
|
||||
err, ok := <-ce
|
||||
if ok {
|
||||
result = err
|
||||
}
|
||||
//fmt.Println("Close: finished")
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *SWbemServices) process(initError chan error) {
|
||||
//fmt.Println("process: starting background thread initialization")
|
||||
//All OLE/WMI calls must happen on the same initialized thead, so lock this goroutine
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
|
||||
if err != nil {
|
||||
oleCode := err.(*ole.OleError).Code()
|
||||
if oleCode != ole.S_OK && oleCode != S_FALSE {
|
||||
initError <- fmt.Errorf("ole.CoInitializeEx error: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
defer ole.CoUninitialize()
|
||||
|
||||
unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
|
||||
if err != nil {
|
||||
initError <- fmt.Errorf("CreateObject SWbemLocator error: %v", err)
|
||||
return
|
||||
} else if unknown == nil {
|
||||
initError <- ErrNilCreateObject
|
||||
return
|
||||
}
|
||||
defer unknown.Release()
|
||||
s.sWbemLocatorIUnknown = unknown
|
||||
|
||||
dispatch, err := s.sWbemLocatorIUnknown.QueryInterface(ole.IID_IDispatch)
|
||||
if err != nil {
|
||||
initError <- fmt.Errorf("SWbemLocator QueryInterface error: %v", err)
|
||||
return
|
||||
}
|
||||
defer dispatch.Release()
|
||||
s.sWbemLocatorIDispatch = dispatch
|
||||
|
||||
// we can't do the ConnectServer call outside the loop unless we find a way to track and re-init the connectServerArgs
|
||||
//fmt.Println("process: initialized. closing initError")
|
||||
close(initError)
|
||||
//fmt.Println("process: waiting for queries")
|
||||
for q := range s.queries {
|
||||
//fmt.Printf("process: new query: len(query)=%d\n", len(q.query))
|
||||
errQuery := s.queryBackground(q)
|
||||
//fmt.Println("process: s.queryBackground finished")
|
||||
if errQuery != nil {
|
||||
q.finished <- errQuery
|
||||
}
|
||||
close(q.finished)
|
||||
}
|
||||
//fmt.Println("process: queries channel closed")
|
||||
s.queries = nil //set channel to nil so we know it is closed
|
||||
//TODO: I think the Release/Clear calls can panic if things are in a bad state.
|
||||
//TODO: May need to recover from panics and send error to method caller instead.
|
||||
close(s.closeError)
|
||||
}
|
||||
|
||||
// Query runs the WQL query using a SWbemServices instance and appends the values to dst.
|
||||
//
|
||||
// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
|
||||
// the query must have the same name in dst. Supported types are all signed and
|
||||
// unsigned integers, time.Time, string, bool, or a pointer to one of those.
|
||||
// Array types are not supported.
|
||||
//
|
||||
// By default, the local machine and default namespace are used. These can be
|
||||
// changed using connectServerArgs. See
|
||||
// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
|
||||
func (s *SWbemServices) Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
|
||||
s.lQueryorClose.Lock()
|
||||
if s == nil || s.sWbemLocatorIDispatch == nil {
|
||||
s.lQueryorClose.Unlock()
|
||||
return fmt.Errorf("SWbemServices is not Initialized")
|
||||
}
|
||||
if s.queries == nil {
|
||||
s.lQueryorClose.Unlock()
|
||||
return fmt.Errorf("SWbemServices has been closed")
|
||||
}
|
||||
|
||||
//fmt.Println("Query: Sending query request")
|
||||
qr := queryRequest{
|
||||
query: query,
|
||||
dst: dst,
|
||||
args: connectServerArgs,
|
||||
finished: make(chan error),
|
||||
}
|
||||
s.queries <- &qr
|
||||
s.lQueryorClose.Unlock()
|
||||
err, ok := <-qr.finished
|
||||
if ok {
|
||||
//fmt.Println("Query: Finished with error")
|
||||
return err //Send error to caller
|
||||
}
|
||||
//fmt.Println("Query: Finished")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SWbemServices) queryBackground(q *queryRequest) error {
|
||||
if s == nil || s.sWbemLocatorIDispatch == nil {
|
||||
return fmt.Errorf("SWbemServices is not Initialized")
|
||||
}
|
||||
wmi := s.sWbemLocatorIDispatch //Should just rename in the code, but this will help as we break things apart
|
||||
//fmt.Println("queryBackground: Starting")
|
||||
|
||||
dv := reflect.ValueOf(q.dst)
|
||||
if dv.Kind() != reflect.Ptr || dv.IsNil() {
|
||||
return ErrInvalidEntityType
|
||||
}
|
||||
dv = dv.Elem()
|
||||
mat, elemType := checkMultiArg(dv)
|
||||
if mat == multiArgTypeInvalid {
|
||||
return ErrInvalidEntityType
|
||||
}
|
||||
|
||||
// service is a SWbemServices
|
||||
serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", q.args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service := serviceRaw.ToIDispatch()
|
||||
defer serviceRaw.Clear()
|
||||
|
||||
// result is a SWBemObjectSet
|
||||
resultRaw, err := oleutil.CallMethod(service, "ExecQuery", q.query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := resultRaw.ToIDispatch()
|
||||
defer resultRaw.Clear()
|
||||
|
||||
count, err := oleInt64(result, "Count")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
enumProperty, err := result.GetProperty("_NewEnum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer enumProperty.Clear()
|
||||
|
||||
enum, err := enumProperty.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if enum == nil {
|
||||
return fmt.Errorf("can't get IEnumVARIANT, enum is nil")
|
||||
}
|
||||
defer enum.Release()
|
||||
|
||||
// Initialize a slice with Count capacity
|
||||
dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count)))
|
||||
|
||||
var errFieldMismatch error
|
||||
for itemRaw, length, err := enum.Next(1); length > 0; itemRaw, length, err = enum.Next(1) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := func() error {
|
||||
// item is a SWbemObject, but really a Win32_Process
|
||||
item := itemRaw.ToIDispatch()
|
||||
defer item.Release()
|
||||
|
||||
ev := reflect.New(elemType)
|
||||
if err = s.cWMIClient.loadEntity(ev.Interface(), item); err != nil {
|
||||
if _, ok := err.(*ErrFieldMismatch); ok {
|
||||
// We continue loading entities even in the face of field mismatch errors.
|
||||
// If we encounter any other error, that other error is returned. Otherwise,
|
||||
// an ErrFieldMismatch is returned.
|
||||
errFieldMismatch = err
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if mat != multiArgTypeStructPtr {
|
||||
ev = ev.Elem()
|
||||
}
|
||||
dv.Set(reflect.Append(dv, ev))
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
//fmt.Println("queryBackground: Finished")
|
||||
return errFieldMismatch
|
||||
}
|
501
vendor/github.com/StackExchange/wmi/wmi.go
generated
vendored
501
vendor/github.com/StackExchange/wmi/wmi.go
generated
vendored
@ -1,501 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Package wmi provides a WQL interface for WMI on Windows.
|
||||
|
||||
Example code to print names of running processes:
|
||||
|
||||
type Win32_Process struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
var dst []Win32_Process
|
||||
q := wmi.CreateQuery(&dst, "")
|
||||
err := wmi.Query(q, &dst)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for i, v := range dst {
|
||||
println(i, v.Name)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
package wmi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
)
|
||||
|
||||
var l = log.New(os.Stdout, "", log.LstdFlags)
|
||||
|
||||
var (
|
||||
ErrInvalidEntityType = errors.New("wmi: invalid entity type")
|
||||
// ErrNilCreateObject is the error returned if CreateObject returns nil even
|
||||
// if the error was nil.
|
||||
ErrNilCreateObject = errors.New("wmi: create object returned nil")
|
||||
lock sync.Mutex
|
||||
)
|
||||
|
||||
// S_FALSE is returned by CoInitializeEx if it was already called on this thread.
|
||||
const S_FALSE = 0x00000001
|
||||
|
||||
// QueryNamespace invokes Query with the given namespace on the local machine.
|
||||
func QueryNamespace(query string, dst interface{}, namespace string) error {
|
||||
return Query(query, dst, nil, namespace)
|
||||
}
|
||||
|
||||
// Query runs the WQL query and appends the values to dst.
|
||||
//
|
||||
// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
|
||||
// the query must have the same name in dst. Supported types are all signed and
|
||||
// unsigned integers, time.Time, string, bool, or a pointer to one of those.
|
||||
// Array types are not supported.
|
||||
//
|
||||
// By default, the local machine and default namespace are used. These can be
|
||||
// changed using connectServerArgs. See
|
||||
// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
|
||||
//
|
||||
// Query is a wrapper around DefaultClient.Query.
|
||||
func Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
|
||||
if DefaultClient.SWbemServicesClient == nil {
|
||||
return DefaultClient.Query(query, dst, connectServerArgs...)
|
||||
}
|
||||
return DefaultClient.SWbemServicesClient.Query(query, dst, connectServerArgs...)
|
||||
}
|
||||
|
||||
// A Client is an WMI query client.
|
||||
//
|
||||
// Its zero value (DefaultClient) is a usable client.
|
||||
type Client struct {
|
||||
// NonePtrZero specifies if nil values for fields which aren't pointers
|
||||
// should be returned as the field types zero value.
|
||||
//
|
||||
// Setting this to true allows stucts without pointer fields to be used
|
||||
// without the risk failure should a nil value returned from WMI.
|
||||
NonePtrZero bool
|
||||
|
||||
// PtrNil specifies if nil values for pointer fields should be returned
|
||||
// as nil.
|
||||
//
|
||||
// Setting this to true will set pointer fields to nil where WMI
|
||||
// returned nil, otherwise the types zero value will be returned.
|
||||
PtrNil bool
|
||||
|
||||
// AllowMissingFields specifies that struct fields not present in the
|
||||
// query result should not result in an error.
|
||||
//
|
||||
// Setting this to true allows custom queries to be used with full
|
||||
// struct definitions instead of having to define multiple structs.
|
||||
AllowMissingFields bool
|
||||
|
||||
// SWbemServiceClient is an optional SWbemServices object that can be
|
||||
// initialized and then reused across multiple queries. If it is null
|
||||
// then the method will initialize a new temporary client each time.
|
||||
SWbemServicesClient *SWbemServices
|
||||
}
|
||||
|
||||
// DefaultClient is the default Client and is used by Query, QueryNamespace
|
||||
var DefaultClient = &Client{}
|
||||
|
||||
// Query runs the WQL query and appends the values to dst.
|
||||
//
|
||||
// dst must have type *[]S or *[]*S, for some struct type S. Fields selected in
|
||||
// the query must have the same name in dst. Supported types are all signed and
|
||||
// unsigned integers, time.Time, string, bool, or a pointer to one of those.
|
||||
// Array types are not supported.
|
||||
//
|
||||
// By default, the local machine and default namespace are used. These can be
|
||||
// changed using connectServerArgs. See
|
||||
// http://msdn.microsoft.com/en-us/library/aa393720.aspx for details.
|
||||
func (c *Client) Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
|
||||
dv := reflect.ValueOf(dst)
|
||||
if dv.Kind() != reflect.Ptr || dv.IsNil() {
|
||||
return ErrInvalidEntityType
|
||||
}
|
||||
dv = dv.Elem()
|
||||
mat, elemType := checkMultiArg(dv)
|
||||
if mat == multiArgTypeInvalid {
|
||||
return ErrInvalidEntityType
|
||||
}
|
||||
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
|
||||
if err != nil {
|
||||
oleCode := err.(*ole.OleError).Code()
|
||||
if oleCode != ole.S_OK && oleCode != S_FALSE {
|
||||
return err
|
||||
}
|
||||
}
|
||||
defer ole.CoUninitialize()
|
||||
|
||||
unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator")
|
||||
if err != nil {
|
||||
return err
|
||||
} else if unknown == nil {
|
||||
return ErrNilCreateObject
|
||||
}
|
||||
defer unknown.Release()
|
||||
|
||||
wmi, err := unknown.QueryInterface(ole.IID_IDispatch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wmi.Release()
|
||||
|
||||
// service is a SWbemServices
|
||||
serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", connectServerArgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service := serviceRaw.ToIDispatch()
|
||||
defer serviceRaw.Clear()
|
||||
|
||||
// result is a SWBemObjectSet
|
||||
resultRaw, err := oleutil.CallMethod(service, "ExecQuery", query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := resultRaw.ToIDispatch()
|
||||
defer resultRaw.Clear()
|
||||
|
||||
count, err := oleInt64(result, "Count")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
enumProperty, err := result.GetProperty("_NewEnum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer enumProperty.Clear()
|
||||
|
||||
enum, err := enumProperty.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if enum == nil {
|
||||
return fmt.Errorf("can't get IEnumVARIANT, enum is nil")
|
||||
}
|
||||
defer enum.Release()
|
||||
|
||||
// Initialize a slice with Count capacity
|
||||
dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count)))
|
||||
|
||||
var errFieldMismatch error
|
||||
for itemRaw, length, err := enum.Next(1); length > 0; itemRaw, length, err = enum.Next(1) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := func() error {
|
||||
// item is a SWbemObject, but really a Win32_Process
|
||||
item := itemRaw.ToIDispatch()
|
||||
defer item.Release()
|
||||
|
||||
ev := reflect.New(elemType)
|
||||
if err = c.loadEntity(ev.Interface(), item); err != nil {
|
||||
if _, ok := err.(*ErrFieldMismatch); ok {
|
||||
// We continue loading entities even in the face of field mismatch errors.
|
||||
// If we encounter any other error, that other error is returned. Otherwise,
|
||||
// an ErrFieldMismatch is returned.
|
||||
errFieldMismatch = err
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if mat != multiArgTypeStructPtr {
|
||||
ev = ev.Elem()
|
||||
}
|
||||
dv.Set(reflect.Append(dv, ev))
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return errFieldMismatch
|
||||
}
|
||||
|
||||
// ErrFieldMismatch is returned when a field is to be loaded into a different
|
||||
// type than the one it was stored from, or when a field is missing or
|
||||
// unexported in the destination struct.
|
||||
// StructType is the type of the struct pointed to by the destination argument.
|
||||
type ErrFieldMismatch struct {
|
||||
StructType reflect.Type
|
||||
FieldName string
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (e *ErrFieldMismatch) Error() string {
|
||||
return fmt.Sprintf("wmi: cannot load field %q into a %q: %s",
|
||||
e.FieldName, e.StructType, e.Reason)
|
||||
}
|
||||
|
||||
var timeType = reflect.TypeOf(time.Time{})
|
||||
|
||||
// loadEntity loads a SWbemObject into a struct pointer.
|
||||
func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismatch error) {
|
||||
v := reflect.ValueOf(dst).Elem()
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
of := f
|
||||
isPtr := f.Kind() == reflect.Ptr
|
||||
if isPtr {
|
||||
ptr := reflect.New(f.Type().Elem())
|
||||
f.Set(ptr)
|
||||
f = f.Elem()
|
||||
}
|
||||
n := v.Type().Field(i).Name
|
||||
if !f.CanSet() {
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "CanSet() is false",
|
||||
}
|
||||
}
|
||||
prop, err := oleutil.GetProperty(src, n)
|
||||
if err != nil {
|
||||
if !c.AllowMissingFields {
|
||||
errFieldMismatch = &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "no such struct field",
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
defer prop.Clear()
|
||||
|
||||
if prop.VT == 0x1 { //VT_NULL
|
||||
continue
|
||||
}
|
||||
|
||||
switch val := prop.Value().(type) {
|
||||
case int8, int16, int32, int64, int:
|
||||
v := reflect.ValueOf(val).Int()
|
||||
switch f.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
f.SetInt(v)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
f.SetUint(uint64(v))
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "not an integer class",
|
||||
}
|
||||
}
|
||||
case uint8, uint16, uint32, uint64:
|
||||
v := reflect.ValueOf(val).Uint()
|
||||
switch f.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
f.SetInt(int64(v))
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
f.SetUint(v)
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "not an integer class",
|
||||
}
|
||||
}
|
||||
case string:
|
||||
switch f.Kind() {
|
||||
case reflect.String:
|
||||
f.SetString(val)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
iv, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.SetInt(iv)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
uv, err := strconv.ParseUint(val, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.SetUint(uv)
|
||||
case reflect.Struct:
|
||||
switch f.Type() {
|
||||
case timeType:
|
||||
if len(val) == 25 {
|
||||
mins, err := strconv.Atoi(val[22:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
val = val[:22] + fmt.Sprintf("%02d%02d", mins/60, mins%60)
|
||||
}
|
||||
t, err := time.Parse("20060102150405.000000-0700", val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.Set(reflect.ValueOf(t))
|
||||
}
|
||||
}
|
||||
case bool:
|
||||
switch f.Kind() {
|
||||
case reflect.Bool:
|
||||
f.SetBool(val)
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "not a bool",
|
||||
}
|
||||
}
|
||||
case float32:
|
||||
switch f.Kind() {
|
||||
case reflect.Float32:
|
||||
f.SetFloat(float64(val))
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "not a Float32",
|
||||
}
|
||||
}
|
||||
default:
|
||||
if f.Kind() == reflect.Slice {
|
||||
switch f.Type().Elem().Kind() {
|
||||
case reflect.String:
|
||||
safeArray := prop.ToArray()
|
||||
if safeArray != nil {
|
||||
arr := safeArray.ToValueArray()
|
||||
fArr := reflect.MakeSlice(f.Type(), len(arr), len(arr))
|
||||
for i, v := range arr {
|
||||
s := fArr.Index(i)
|
||||
s.SetString(v.(string))
|
||||
}
|
||||
f.Set(fArr)
|
||||
}
|
||||
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
|
||||
safeArray := prop.ToArray()
|
||||
if safeArray != nil {
|
||||
arr := safeArray.ToValueArray()
|
||||
fArr := reflect.MakeSlice(f.Type(), len(arr), len(arr))
|
||||
for i, v := range arr {
|
||||
s := fArr.Index(i)
|
||||
s.SetUint(reflect.ValueOf(v).Uint())
|
||||
}
|
||||
f.Set(fArr)
|
||||
}
|
||||
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
|
||||
safeArray := prop.ToArray()
|
||||
if safeArray != nil {
|
||||
arr := safeArray.ToValueArray()
|
||||
fArr := reflect.MakeSlice(f.Type(), len(arr), len(arr))
|
||||
for i, v := range arr {
|
||||
s := fArr.Index(i)
|
||||
s.SetInt(reflect.ValueOf(v).Int())
|
||||
}
|
||||
f.Set(fArr)
|
||||
}
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: fmt.Sprintf("unsupported slice type (%T)", val),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
typeof := reflect.TypeOf(val)
|
||||
if typeof == nil && (isPtr || c.NonePtrZero) {
|
||||
if (isPtr && c.PtrNil) || (!isPtr && c.NonePtrZero) {
|
||||
of.Set(reflect.Zero(of.Type()))
|
||||
}
|
||||
break
|
||||
}
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: fmt.Sprintf("unsupported type (%T)", val),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errFieldMismatch
|
||||
}
|
||||
|
||||
type multiArgType int
|
||||
|
||||
const (
|
||||
multiArgTypeInvalid multiArgType = iota
|
||||
multiArgTypeStruct
|
||||
multiArgTypeStructPtr
|
||||
)
|
||||
|
||||
// checkMultiArg checks that v has type []S, []*S for some struct type S.
|
||||
//
|
||||
// It returns what category the slice's elements are, and the reflect.Type
|
||||
// that represents S.
|
||||
func checkMultiArg(v reflect.Value) (m multiArgType, elemType reflect.Type) {
|
||||
if v.Kind() != reflect.Slice {
|
||||
return multiArgTypeInvalid, nil
|
||||
}
|
||||
elemType = v.Type().Elem()
|
||||
switch elemType.Kind() {
|
||||
case reflect.Struct:
|
||||
return multiArgTypeStruct, elemType
|
||||
case reflect.Ptr:
|
||||
elemType = elemType.Elem()
|
||||
if elemType.Kind() == reflect.Struct {
|
||||
return multiArgTypeStructPtr, elemType
|
||||
}
|
||||
}
|
||||
return multiArgTypeInvalid, nil
|
||||
}
|
||||
|
||||
func oleInt64(item *ole.IDispatch, prop string) (int64, error) {
|
||||
v, err := oleutil.GetProperty(item, prop)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer v.Clear()
|
||||
|
||||
i := int64(v.Val)
|
||||
return i, nil
|
||||
}
|
||||
|
||||
// CreateQuery returns a WQL query string that queries all columns of src. where
|
||||
// is an optional string that is appended to the query, to be used with WHERE
|
||||
// clauses. In such a case, the "WHERE" string should appear at the beginning.
|
||||
func CreateQuery(src interface{}, where string) string {
|
||||
var b bytes.Buffer
|
||||
b.WriteString("SELECT ")
|
||||
s := reflect.Indirect(reflect.ValueOf(src))
|
||||
t := s.Type()
|
||||
if s.Kind() == reflect.Slice {
|
||||
t = t.Elem()
|
||||
}
|
||||
if t.Kind() != reflect.Struct {
|
||||
return ""
|
||||
}
|
||||
var fields []string
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
fields = append(fields, t.Field(i).Name)
|
||||
}
|
||||
b.WriteString(strings.Join(fields, ", "))
|
||||
b.WriteString(" FROM ")
|
||||
b.WriteString(t.Name())
|
||||
b.WriteString(" " + where)
|
||||
return b.String()
|
||||
}
|
8
vendor/github.com/go-ole/go-ole/.travis.yml
generated
vendored
8
vendor/github.com/go-ole/go-ole/.travis.yml
generated
vendored
@ -1,8 +0,0 @@
|
||||
language: go
|
||||
sudo: false
|
||||
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- tip
|
49
vendor/github.com/go-ole/go-ole/ChangeLog.md
generated
vendored
49
vendor/github.com/go-ole/go-ole/ChangeLog.md
generated
vendored
@ -1,49 +0,0 @@
|
||||
# Version 1.x.x
|
||||
|
||||
* **Add more test cases and reference new test COM server project.** (Placeholder for future additions)
|
||||
|
||||
# Version 1.2.0-alphaX
|
||||
|
||||
**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.**
|
||||
|
||||
* Added CI configuration for Travis-CI and AppVeyor.
|
||||
* Added test InterfaceID and ClassID for the COM Test Server project.
|
||||
* Added more inline documentation (#83).
|
||||
* Added IEnumVARIANT implementation (#88).
|
||||
* Added IEnumVARIANT test cases (#99, #100, #101).
|
||||
* Added support for retrieving `time.Time` from VARIANT (#92).
|
||||
* Added test case for IUnknown (#64).
|
||||
* Added test case for IDispatch (#64).
|
||||
* Added test cases for scalar variants (#64, #76).
|
||||
|
||||
# Version 1.1.1
|
||||
|
||||
* Fixes for Linux build.
|
||||
* Fixes for Windows build.
|
||||
|
||||
# Version 1.1.0
|
||||
|
||||
The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes.
|
||||
|
||||
* Move GUID out of variables.go into its own file to make new documentation available.
|
||||
* Move OleError out of ole.go into its own file to make new documentation available.
|
||||
* Add documentation to utility functions.
|
||||
* Add documentation to variant receiver functions.
|
||||
* Add documentation to ole structures.
|
||||
* Make variant available to other systems outside of Windows.
|
||||
* Make OLE structures available to other systems outside of Windows.
|
||||
|
||||
## New Features
|
||||
|
||||
* Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows.
|
||||
* More functions are now documented and available on godoc.org.
|
||||
|
||||
# Version 1.0.1
|
||||
|
||||
1. Fix package references from repository location change.
|
||||
|
||||
# Version 1.0.0
|
||||
|
||||
This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface.
|
||||
|
||||
There is no changelog for this version. Check commits for history.
|
21
vendor/github.com/go-ole/go-ole/LICENSE
generated
vendored
21
vendor/github.com/go-ole/go-ole/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright © 2013-2017 Yasuhiro Matsumoto, <mattn.jp@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the “Software”), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
46
vendor/github.com/go-ole/go-ole/README.md
generated
vendored
46
vendor/github.com/go-ole/go-ole/README.md
generated
vendored
@ -1,46 +0,0 @@
|
||||
# Go OLE
|
||||
|
||||
[](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28)
|
||||
[](https://travis-ci.org/go-ole/go-ole)
|
||||
[](https://godoc.org/github.com/go-ole/go-ole)
|
||||
|
||||
Go bindings for Windows COM using shared libraries instead of cgo.
|
||||
|
||||
By Yasuhiro Matsumoto.
|
||||
|
||||
## Install
|
||||
|
||||
To experiment with go-ole, you can just compile and run the example program:
|
||||
|
||||
```
|
||||
go get github.com/go-ole/go-ole
|
||||
cd /path/to/go-ole/
|
||||
go test
|
||||
|
||||
cd /path/to/go-ole/example/excel
|
||||
go run excel.go
|
||||
```
|
||||
|
||||
## Continuous Integration
|
||||
|
||||
Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run.
|
||||
|
||||
**Travis-CI**
|
||||
|
||||
Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server.
|
||||
|
||||
**AppVeyor**
|
||||
|
||||
AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server.
|
||||
|
||||
The tests currently do run and do pass and this should be maintained with commits.
|
||||
|
||||
## Versioning
|
||||
|
||||
Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.
|
||||
|
||||
This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.
|
||||
|
||||
## LICENSE
|
||||
|
||||
Under the MIT License: http://mattn.mit-license.org/2013
|
54
vendor/github.com/go-ole/go-ole/appveyor.yml
generated
vendored
54
vendor/github.com/go-ole/go-ole/appveyor.yml
generated
vendored
@ -1,54 +0,0 @@
|
||||
# Notes:
|
||||
# - Minimal appveyor.yml file is an empty file. All sections are optional.
|
||||
# - Indent each level of configuration with 2 spaces. Do not use tabs!
|
||||
# - All section names are case-sensitive.
|
||||
# - Section names should be unique on each level.
|
||||
|
||||
version: "1.3.0.{build}-alpha-{branch}"
|
||||
|
||||
os: Windows Server 2012 R2
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- v1.2
|
||||
- v1.1
|
||||
- v1.0
|
||||
|
||||
skip_tags: true
|
||||
|
||||
clone_folder: c:\gopath\src\github.com\go-ole\go-ole
|
||||
|
||||
environment:
|
||||
GOPATH: c:\gopath
|
||||
matrix:
|
||||
- GOARCH: amd64
|
||||
GOVERSION: 1.5
|
||||
GOROOT: c:\go
|
||||
DOWNLOADPLATFORM: "x64"
|
||||
|
||||
install:
|
||||
- choco install mingw
|
||||
- SET PATH=c:\tools\mingw64\bin;%PATH%
|
||||
# - Download COM Server
|
||||
- ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.2/test-com-server-${env:DOWNLOADPLATFORM}.zip"
|
||||
- 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL
|
||||
- c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat
|
||||
# - set
|
||||
- go version
|
||||
- go env
|
||||
- go get -u golang.org/x/tools/cmd/cover
|
||||
- go get -u golang.org/x/tools/cmd/godoc
|
||||
- go get -u golang.org/x/tools/cmd/stringer
|
||||
|
||||
build_script:
|
||||
- cd c:\gopath\src\github.com\go-ole\go-ole
|
||||
- go get -v -t ./...
|
||||
- go build
|
||||
- go test -v -cover ./...
|
||||
|
||||
# disable automatic tests
|
||||
test: off
|
||||
|
||||
# disable deployment
|
||||
deploy: off
|
344
vendor/github.com/go-ole/go-ole/com.go
generated
vendored
344
vendor/github.com/go-ole/go-ole/com.go
generated
vendored
@ -1,344 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unicode/utf16"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
procCoInitialize, _ = modole32.FindProc("CoInitialize")
|
||||
procCoInitializeEx, _ = modole32.FindProc("CoInitializeEx")
|
||||
procCoUninitialize, _ = modole32.FindProc("CoUninitialize")
|
||||
procCoCreateInstance, _ = modole32.FindProc("CoCreateInstance")
|
||||
procCoTaskMemFree, _ = modole32.FindProc("CoTaskMemFree")
|
||||
procCLSIDFromProgID, _ = modole32.FindProc("CLSIDFromProgID")
|
||||
procCLSIDFromString, _ = modole32.FindProc("CLSIDFromString")
|
||||
procStringFromCLSID, _ = modole32.FindProc("StringFromCLSID")
|
||||
procStringFromIID, _ = modole32.FindProc("StringFromIID")
|
||||
procIIDFromString, _ = modole32.FindProc("IIDFromString")
|
||||
procCoGetObject, _ = modole32.FindProc("CoGetObject")
|
||||
procGetUserDefaultLCID, _ = modkernel32.FindProc("GetUserDefaultLCID")
|
||||
procCopyMemory, _ = modkernel32.FindProc("RtlMoveMemory")
|
||||
procVariantInit, _ = modoleaut32.FindProc("VariantInit")
|
||||
procVariantClear, _ = modoleaut32.FindProc("VariantClear")
|
||||
procVariantTimeToSystemTime, _ = modoleaut32.FindProc("VariantTimeToSystemTime")
|
||||
procSysAllocString, _ = modoleaut32.FindProc("SysAllocString")
|
||||
procSysAllocStringLen, _ = modoleaut32.FindProc("SysAllocStringLen")
|
||||
procSysFreeString, _ = modoleaut32.FindProc("SysFreeString")
|
||||
procSysStringLen, _ = modoleaut32.FindProc("SysStringLen")
|
||||
procCreateDispTypeInfo, _ = modoleaut32.FindProc("CreateDispTypeInfo")
|
||||
procCreateStdDispatch, _ = modoleaut32.FindProc("CreateStdDispatch")
|
||||
procGetActiveObject, _ = modoleaut32.FindProc("GetActiveObject")
|
||||
|
||||
procGetMessageW, _ = moduser32.FindProc("GetMessageW")
|
||||
procDispatchMessageW, _ = moduser32.FindProc("DispatchMessageW")
|
||||
)
|
||||
|
||||
// coInitialize initializes COM library on current thread.
|
||||
//
|
||||
// MSDN documentation suggests that this function should not be called. Call
|
||||
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||
// function is only for single-threaded apartments.
|
||||
//
|
||||
// That said, most users of the library have gotten away with just this
|
||||
// function. If you are experiencing threading issues, then use
|
||||
// CoInitializeEx().
|
||||
func coInitialize() (err error) {
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx
|
||||
// Suggests that no value should be passed to CoInitialized.
|
||||
// Could just be Call() since the parameter is optional. <-- Needs testing to be sure.
|
||||
hr, _, _ := procCoInitialize.Call(uintptr(0))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// coInitializeEx initializes COM library with concurrency model.
|
||||
func coInitializeEx(coinit uint32) (err error) {
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx
|
||||
// Suggests that the first parameter is not only optional but should always be NULL.
|
||||
hr, _, _ := procCoInitializeEx.Call(uintptr(0), uintptr(coinit))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CoInitialize initializes COM library on current thread.
|
||||
//
|
||||
// MSDN documentation suggests that this function should not be called. Call
|
||||
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||
// function is only for single-threaded apartments.
|
||||
//
|
||||
// That said, most users of the library have gotten away with just this
|
||||
// function. If you are experiencing threading issues, then use
|
||||
// CoInitializeEx().
|
||||
func CoInitialize(p uintptr) (err error) {
|
||||
// p is ignored and won't be used.
|
||||
// Avoid any variable not used errors.
|
||||
p = uintptr(0)
|
||||
return coInitialize()
|
||||
}
|
||||
|
||||
// CoInitializeEx initializes COM library with concurrency model.
|
||||
func CoInitializeEx(p uintptr, coinit uint32) (err error) {
|
||||
// Avoid any variable not used errors.
|
||||
p = uintptr(0)
|
||||
return coInitializeEx(coinit)
|
||||
}
|
||||
|
||||
// CoUninitialize uninitializes COM Library.
|
||||
func CoUninitialize() {
|
||||
procCoUninitialize.Call()
|
||||
}
|
||||
|
||||
// CoTaskMemFree frees memory pointer.
|
||||
func CoTaskMemFree(memptr uintptr) {
|
||||
procCoTaskMemFree.Call(memptr)
|
||||
}
|
||||
|
||||
// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
|
||||
//
|
||||
// The Programmatic Identifier must be registered, because it will be looked up
|
||||
// in the Windows Registry. The registry entry has the following keys: CLSID,
|
||||
// Insertable, Protocol and Shell
|
||||
// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
|
||||
//
|
||||
// programID identifies the class id with less precision and is not guaranteed
|
||||
// to be unique. These are usually found in the registry under
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
|
||||
// "Program.Component.Version" with version being optional.
|
||||
//
|
||||
// CLSIDFromProgID in Windows API.
|
||||
func CLSIDFromProgID(progId string) (clsid *GUID, err error) {
|
||||
var guid GUID
|
||||
lpszProgID := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
|
||||
hr, _, _ := procCLSIDFromProgID.Call(lpszProgID, uintptr(unsafe.Pointer(&guid)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
clsid = &guid
|
||||
return
|
||||
}
|
||||
|
||||
// CLSIDFromString retrieves Class ID from string representation.
|
||||
//
|
||||
// This is technically the string version of the GUID and will convert the
|
||||
// string to object.
|
||||
//
|
||||
// CLSIDFromString in Windows API.
|
||||
func CLSIDFromString(str string) (clsid *GUID, err error) {
|
||||
var guid GUID
|
||||
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
|
||||
hr, _, _ := procCLSIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
clsid = &guid
|
||||
return
|
||||
}
|
||||
|
||||
// StringFromCLSID returns GUID formated string from GUID object.
|
||||
func StringFromCLSID(clsid *GUID) (str string, err error) {
|
||||
var p *uint16
|
||||
hr, _, _ := procStringFromCLSID.Call(uintptr(unsafe.Pointer(clsid)), uintptr(unsafe.Pointer(&p)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
str = LpOleStrToString(p)
|
||||
return
|
||||
}
|
||||
|
||||
// IIDFromString returns GUID from program ID.
|
||||
func IIDFromString(progId string) (clsid *GUID, err error) {
|
||||
var guid GUID
|
||||
lpsz := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(progId)))
|
||||
hr, _, _ := procIIDFromString.Call(lpsz, uintptr(unsafe.Pointer(&guid)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
clsid = &guid
|
||||
return
|
||||
}
|
||||
|
||||
// StringFromIID returns GUID formatted string from GUID object.
|
||||
func StringFromIID(iid *GUID) (str string, err error) {
|
||||
var p *uint16
|
||||
hr, _, _ := procStringFromIID.Call(uintptr(unsafe.Pointer(iid)), uintptr(unsafe.Pointer(&p)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
str = LpOleStrToString(p)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateInstance of single uninitialized object with GUID.
|
||||
func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||
if iid == nil {
|
||||
iid = IID_IUnknown
|
||||
}
|
||||
hr, _, _ := procCoCreateInstance.Call(
|
||||
uintptr(unsafe.Pointer(clsid)),
|
||||
0,
|
||||
CLSCTX_SERVER,
|
||||
uintptr(unsafe.Pointer(iid)),
|
||||
uintptr(unsafe.Pointer(&unk)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetActiveObject retrieves pointer to active object.
|
||||
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||
if iid == nil {
|
||||
iid = IID_IUnknown
|
||||
}
|
||||
hr, _, _ := procGetActiveObject.Call(
|
||||
uintptr(unsafe.Pointer(clsid)),
|
||||
uintptr(unsafe.Pointer(iid)),
|
||||
uintptr(unsafe.Pointer(&unk)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type BindOpts struct {
|
||||
CbStruct uint32
|
||||
GrfFlags uint32
|
||||
GrfMode uint32
|
||||
TickCountDeadline uint32
|
||||
}
|
||||
|
||||
// GetObject retrieves pointer to active object.
|
||||
func GetObject(programID string, bindOpts *BindOpts, iid *GUID) (unk *IUnknown, err error) {
|
||||
if bindOpts != nil {
|
||||
bindOpts.CbStruct = uint32(unsafe.Sizeof(BindOpts{}))
|
||||
}
|
||||
if iid == nil {
|
||||
iid = IID_IUnknown
|
||||
}
|
||||
hr, _, _ := procCoGetObject.Call(
|
||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(programID))),
|
||||
uintptr(unsafe.Pointer(bindOpts)),
|
||||
uintptr(unsafe.Pointer(iid)),
|
||||
uintptr(unsafe.Pointer(&unk)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// VariantInit initializes variant.
|
||||
func VariantInit(v *VARIANT) (err error) {
|
||||
hr, _, _ := procVariantInit.Call(uintptr(unsafe.Pointer(v)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// VariantClear clears value in Variant settings to VT_EMPTY.
|
||||
func VariantClear(v *VARIANT) (err error) {
|
||||
hr, _, _ := procVariantClear.Call(uintptr(unsafe.Pointer(v)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SysAllocString allocates memory for string and copies string into memory.
|
||||
func SysAllocString(v string) (ss *int16) {
|
||||
pss, _, _ := procSysAllocString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(v))))
|
||||
ss = (*int16)(unsafe.Pointer(pss))
|
||||
return
|
||||
}
|
||||
|
||||
// SysAllocStringLen copies up to length of given string returning pointer.
|
||||
func SysAllocStringLen(v string) (ss *int16) {
|
||||
utf16 := utf16.Encode([]rune(v + "\x00"))
|
||||
ptr := &utf16[0]
|
||||
|
||||
pss, _, _ := procSysAllocStringLen.Call(uintptr(unsafe.Pointer(ptr)), uintptr(len(utf16)-1))
|
||||
ss = (*int16)(unsafe.Pointer(pss))
|
||||
return
|
||||
}
|
||||
|
||||
// SysFreeString frees string system memory. This must be called with SysAllocString.
|
||||
func SysFreeString(v *int16) (err error) {
|
||||
hr, _, _ := procSysFreeString.Call(uintptr(unsafe.Pointer(v)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SysStringLen is the length of the system allocated string.
|
||||
func SysStringLen(v *int16) uint32 {
|
||||
l, _, _ := procSysStringLen.Call(uintptr(unsafe.Pointer(v)))
|
||||
return uint32(l)
|
||||
}
|
||||
|
||||
// CreateStdDispatch provides default IDispatch implementation for IUnknown.
|
||||
//
|
||||
// This handles default IDispatch implementation for objects. It haves a few
|
||||
// limitations with only supporting one language. It will also only return
|
||||
// default exception codes.
|
||||
func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (disp *IDispatch, err error) {
|
||||
hr, _, _ := procCreateStdDispatch.Call(
|
||||
uintptr(unsafe.Pointer(unk)),
|
||||
v,
|
||||
uintptr(unsafe.Pointer(ptinfo)),
|
||||
uintptr(unsafe.Pointer(&disp)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
|
||||
//
|
||||
// This will not handle the full implementation of the interface.
|
||||
func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
|
||||
hr, _, _ := procCreateDispTypeInfo.Call(
|
||||
uintptr(unsafe.Pointer(idata)),
|
||||
uintptr(GetUserDefaultLCID()),
|
||||
uintptr(unsafe.Pointer(&pptinfo)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// copyMemory moves location of a block of memory.
|
||||
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
|
||||
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
|
||||
}
|
||||
|
||||
// GetUserDefaultLCID retrieves current user default locale.
|
||||
func GetUserDefaultLCID() (lcid uint32) {
|
||||
ret, _, _ := procGetUserDefaultLCID.Call()
|
||||
lcid = uint32(ret)
|
||||
return
|
||||
}
|
||||
|
||||
// GetMessage in message queue from runtime.
|
||||
//
|
||||
// This function appears to block. PeekMessage does not block.
|
||||
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
|
||||
r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
|
||||
ret = int32(r0)
|
||||
return
|
||||
}
|
||||
|
||||
// DispatchMessage to window procedure.
|
||||
func DispatchMessage(msg *Msg) (ret int32) {
|
||||
r0, _, _ := procDispatchMessageW.Call(uintptr(unsafe.Pointer(msg)))
|
||||
ret = int32(r0)
|
||||
return
|
||||
}
|
174
vendor/github.com/go-ole/go-ole/com_func.go
generated
vendored
174
vendor/github.com/go-ole/go-ole/com_func.go
generated
vendored
@ -1,174 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// coInitialize initializes COM library on current thread.
|
||||
//
|
||||
// MSDN documentation suggests that this function should not be called. Call
|
||||
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||
// function is only for single-threaded apartments.
|
||||
//
|
||||
// That said, most users of the library have gotten away with just this
|
||||
// function. If you are experiencing threading issues, then use
|
||||
// CoInitializeEx().
|
||||
func coInitialize() error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// coInitializeEx initializes COM library with concurrency model.
|
||||
func coInitializeEx(coinit uint32) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CoInitialize initializes COM library on current thread.
|
||||
//
|
||||
// MSDN documentation suggests that this function should not be called. Call
|
||||
// CoInitializeEx() instead. The reason has to do with threading and this
|
||||
// function is only for single-threaded apartments.
|
||||
//
|
||||
// That said, most users of the library have gotten away with just this
|
||||
// function. If you are experiencing threading issues, then use
|
||||
// CoInitializeEx().
|
||||
func CoInitialize(p uintptr) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CoInitializeEx initializes COM library with concurrency model.
|
||||
func CoInitializeEx(p uintptr, coinit uint32) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CoUninitialize uninitializes COM Library.
|
||||
func CoUninitialize() {}
|
||||
|
||||
// CoTaskMemFree frees memory pointer.
|
||||
func CoTaskMemFree(memptr uintptr) {}
|
||||
|
||||
// CLSIDFromProgID retrieves Class Identifier with the given Program Identifier.
|
||||
//
|
||||
// The Programmatic Identifier must be registered, because it will be looked up
|
||||
// in the Windows Registry. The registry entry has the following keys: CLSID,
|
||||
// Insertable, Protocol and Shell
|
||||
// (https://msdn.microsoft.com/en-us/library/dd542719(v=vs.85).aspx).
|
||||
//
|
||||
// programID identifies the class id with less precision and is not guaranteed
|
||||
// to be unique. These are usually found in the registry under
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\Classes, usually with the format of
|
||||
// "Program.Component.Version" with version being optional.
|
||||
//
|
||||
// CLSIDFromProgID in Windows API.
|
||||
func CLSIDFromProgID(progId string) (*GUID, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CLSIDFromString retrieves Class ID from string representation.
|
||||
//
|
||||
// This is technically the string version of the GUID and will convert the
|
||||
// string to object.
|
||||
//
|
||||
// CLSIDFromString in Windows API.
|
||||
func CLSIDFromString(str string) (*GUID, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// StringFromCLSID returns GUID formated string from GUID object.
|
||||
func StringFromCLSID(clsid *GUID) (string, error) {
|
||||
return "", NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// IIDFromString returns GUID from program ID.
|
||||
func IIDFromString(progId string) (*GUID, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// StringFromIID returns GUID formatted string from GUID object.
|
||||
func StringFromIID(iid *GUID) (string, error) {
|
||||
return "", NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CreateInstance of single uninitialized object with GUID.
|
||||
func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// GetActiveObject retrieves pointer to active object.
|
||||
func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// VariantInit initializes variant.
|
||||
func VariantInit(v *VARIANT) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// VariantClear clears value in Variant settings to VT_EMPTY.
|
||||
func VariantClear(v *VARIANT) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// SysAllocString allocates memory for string and copies string into memory.
|
||||
func SysAllocString(v string) *int16 {
|
||||
u := int16(0)
|
||||
return &u
|
||||
}
|
||||
|
||||
// SysAllocStringLen copies up to length of given string returning pointer.
|
||||
func SysAllocStringLen(v string) *int16 {
|
||||
u := int16(0)
|
||||
return &u
|
||||
}
|
||||
|
||||
// SysFreeString frees string system memory. This must be called with SysAllocString.
|
||||
func SysFreeString(v *int16) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// SysStringLen is the length of the system allocated string.
|
||||
func SysStringLen(v *int16) uint32 {
|
||||
return uint32(0)
|
||||
}
|
||||
|
||||
// CreateStdDispatch provides default IDispatch implementation for IUnknown.
|
||||
//
|
||||
// This handles default IDispatch implementation for objects. It haves a few
|
||||
// limitations with only supporting one language. It will also only return
|
||||
// default exception codes.
|
||||
func CreateStdDispatch(unk *IUnknown, v uintptr, ptinfo *IUnknown) (*IDispatch, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// CreateDispTypeInfo provides default ITypeInfo implementation for IDispatch.
|
||||
//
|
||||
// This will not handle the full implementation of the interface.
|
||||
func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// copyMemory moves location of a block of memory.
|
||||
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
|
||||
|
||||
// GetUserDefaultLCID retrieves current user default locale.
|
||||
func GetUserDefaultLCID() uint32 {
|
||||
return uint32(0)
|
||||
}
|
||||
|
||||
// GetMessage in message queue from runtime.
|
||||
//
|
||||
// This function appears to block. PeekMessage does not block.
|
||||
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
|
||||
return int32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// DispatchMessage to window procedure.
|
||||
func DispatchMessage(msg *Msg) int32 {
|
||||
return int32(0)
|
||||
}
|
||||
|
||||
func GetVariantDate(value uint64) (time.Time, error) {
|
||||
return time.Now(), NewError(E_NOTIMPL)
|
||||
}
|
192
vendor/github.com/go-ole/go-ole/connect.go
generated
vendored
192
vendor/github.com/go-ole/go-ole/connect.go
generated
vendored
@ -1,192 +0,0 @@
|
||||
package ole
|
||||
|
||||
// Connection contains IUnknown for fluent interface interaction.
|
||||
//
|
||||
// Deprecated. Use oleutil package instead.
|
||||
type Connection struct {
|
||||
Object *IUnknown // Access COM
|
||||
}
|
||||
|
||||
// Initialize COM.
|
||||
func (*Connection) Initialize() (err error) {
|
||||
return coInitialize()
|
||||
}
|
||||
|
||||
// Uninitialize COM.
|
||||
func (*Connection) Uninitialize() {
|
||||
CoUninitialize()
|
||||
}
|
||||
|
||||
// Create IUnknown object based first on ProgId and then from String.
|
||||
func (c *Connection) Create(progId string) (err error) {
|
||||
var clsid *GUID
|
||||
clsid, err = CLSIDFromProgID(progId)
|
||||
if err != nil {
|
||||
clsid, err = CLSIDFromString(progId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
unknown, err := CreateInstance(clsid, IID_IUnknown)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Object = unknown
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Release IUnknown object.
|
||||
func (c *Connection) Release() {
|
||||
c.Object.Release()
|
||||
}
|
||||
|
||||
// Load COM object from list of programIDs or strings.
|
||||
func (c *Connection) Load(names ...string) (errors []error) {
|
||||
var tempErrors []error = make([]error, len(names))
|
||||
var numErrors int = 0
|
||||
for _, name := range names {
|
||||
err := c.Create(name)
|
||||
if err != nil {
|
||||
tempErrors = append(tempErrors, err)
|
||||
numErrors += 1
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
copy(errors, tempErrors[0:numErrors])
|
||||
return
|
||||
}
|
||||
|
||||
// Dispatch returns Dispatch object.
|
||||
func (c *Connection) Dispatch() (object *Dispatch, err error) {
|
||||
dispatch, err := c.Object.QueryInterface(IID_IDispatch)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
object = &Dispatch{dispatch}
|
||||
return
|
||||
}
|
||||
|
||||
// Dispatch stores IDispatch object.
|
||||
type Dispatch struct {
|
||||
Object *IDispatch // Dispatch object.
|
||||
}
|
||||
|
||||
// Call method on IDispatch with parameters.
|
||||
func (d *Dispatch) Call(method string, params ...interface{}) (result *VARIANT, err error) {
|
||||
id, err := d.GetId(method)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
result, err = d.Invoke(id, DISPATCH_METHOD, params)
|
||||
return
|
||||
}
|
||||
|
||||
// MustCall method on IDispatch with parameters.
|
||||
func (d *Dispatch) MustCall(method string, params ...interface{}) (result *VARIANT) {
|
||||
id, err := d.GetId(method)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
result, err = d.Invoke(id, DISPATCH_METHOD, params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get property on IDispatch with parameters.
|
||||
func (d *Dispatch) Get(name string, params ...interface{}) (result *VARIANT, err error) {
|
||||
id, err := d.GetId(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
|
||||
return
|
||||
}
|
||||
|
||||
// MustGet property on IDispatch with parameters.
|
||||
func (d *Dispatch) MustGet(name string, params ...interface{}) (result *VARIANT) {
|
||||
id, err := d.GetId(name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
result, err = d.Invoke(id, DISPATCH_PROPERTYGET, params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Set property on IDispatch with parameters.
|
||||
func (d *Dispatch) Set(name string, params ...interface{}) (result *VARIANT, err error) {
|
||||
id, err := d.GetId(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
|
||||
return
|
||||
}
|
||||
|
||||
// MustSet property on IDispatch with parameters.
|
||||
func (d *Dispatch) MustSet(name string, params ...interface{}) (result *VARIANT) {
|
||||
id, err := d.GetId(name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
result, err = d.Invoke(id, DISPATCH_PROPERTYPUT, params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetId retrieves ID of name on IDispatch.
|
||||
func (d *Dispatch) GetId(name string) (id int32, err error) {
|
||||
var dispid []int32
|
||||
dispid, err = d.Object.GetIDsOfName([]string{name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
id = dispid[0]
|
||||
return
|
||||
}
|
||||
|
||||
// GetIds retrieves all IDs of names on IDispatch.
|
||||
func (d *Dispatch) GetIds(names ...string) (dispid []int32, err error) {
|
||||
dispid, err = d.Object.GetIDsOfName(names)
|
||||
return
|
||||
}
|
||||
|
||||
// Invoke IDispatch on DisplayID of dispatch type with parameters.
|
||||
//
|
||||
// There have been problems where if send cascading params..., it would error
|
||||
// out because the parameters would be empty.
|
||||
func (d *Dispatch) Invoke(id int32, dispatch int16, params []interface{}) (result *VARIANT, err error) {
|
||||
if len(params) < 1 {
|
||||
result, err = d.Object.Invoke(id, dispatch)
|
||||
} else {
|
||||
result, err = d.Object.Invoke(id, dispatch, params...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Release IDispatch object.
|
||||
func (d *Dispatch) Release() {
|
||||
d.Object.Release()
|
||||
}
|
||||
|
||||
// Connect initializes COM and attempts to load IUnknown based on given names.
|
||||
func Connect(names ...string) (connection *Connection) {
|
||||
connection.Initialize()
|
||||
connection.Load(names...)
|
||||
return
|
||||
}
|
153
vendor/github.com/go-ole/go-ole/constants.go
generated
vendored
153
vendor/github.com/go-ole/go-ole/constants.go
generated
vendored
@ -1,153 +0,0 @@
|
||||
package ole
|
||||
|
||||
const (
|
||||
CLSCTX_INPROC_SERVER = 1
|
||||
CLSCTX_INPROC_HANDLER = 2
|
||||
CLSCTX_LOCAL_SERVER = 4
|
||||
CLSCTX_INPROC_SERVER16 = 8
|
||||
CLSCTX_REMOTE_SERVER = 16
|
||||
CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER
|
||||
CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER
|
||||
CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
|
||||
)
|
||||
|
||||
const (
|
||||
COINIT_APARTMENTTHREADED = 0x2
|
||||
COINIT_MULTITHREADED = 0x0
|
||||
COINIT_DISABLE_OLE1DDE = 0x4
|
||||
COINIT_SPEED_OVER_MEMORY = 0x8
|
||||
)
|
||||
|
||||
const (
|
||||
DISPATCH_METHOD = 1
|
||||
DISPATCH_PROPERTYGET = 2
|
||||
DISPATCH_PROPERTYPUT = 4
|
||||
DISPATCH_PROPERTYPUTREF = 8
|
||||
)
|
||||
|
||||
const (
|
||||
S_OK = 0x00000000
|
||||
E_UNEXPECTED = 0x8000FFFF
|
||||
E_NOTIMPL = 0x80004001
|
||||
E_OUTOFMEMORY = 0x8007000E
|
||||
E_INVALIDARG = 0x80070057
|
||||
E_NOINTERFACE = 0x80004002
|
||||
E_POINTER = 0x80004003
|
||||
E_HANDLE = 0x80070006
|
||||
E_ABORT = 0x80004004
|
||||
E_FAIL = 0x80004005
|
||||
E_ACCESSDENIED = 0x80070005
|
||||
E_PENDING = 0x8000000A
|
||||
|
||||
CO_E_CLASSSTRING = 0x800401F3
|
||||
)
|
||||
|
||||
const (
|
||||
CC_FASTCALL = iota
|
||||
CC_CDECL
|
||||
CC_MSCPASCAL
|
||||
CC_PASCAL = CC_MSCPASCAL
|
||||
CC_MACPASCAL
|
||||
CC_STDCALL
|
||||
CC_FPFASTCALL
|
||||
CC_SYSCALL
|
||||
CC_MPWCDECL
|
||||
CC_MPWPASCAL
|
||||
CC_MAX = CC_MPWPASCAL
|
||||
)
|
||||
|
||||
type VT uint16
|
||||
|
||||
const (
|
||||
VT_EMPTY VT = 0x0
|
||||
VT_NULL VT = 0x1
|
||||
VT_I2 VT = 0x2
|
||||
VT_I4 VT = 0x3
|
||||
VT_R4 VT = 0x4
|
||||
VT_R8 VT = 0x5
|
||||
VT_CY VT = 0x6
|
||||
VT_DATE VT = 0x7
|
||||
VT_BSTR VT = 0x8
|
||||
VT_DISPATCH VT = 0x9
|
||||
VT_ERROR VT = 0xa
|
||||
VT_BOOL VT = 0xb
|
||||
VT_VARIANT VT = 0xc
|
||||
VT_UNKNOWN VT = 0xd
|
||||
VT_DECIMAL VT = 0xe
|
||||
VT_I1 VT = 0x10
|
||||
VT_UI1 VT = 0x11
|
||||
VT_UI2 VT = 0x12
|
||||
VT_UI4 VT = 0x13
|
||||
VT_I8 VT = 0x14
|
||||
VT_UI8 VT = 0x15
|
||||
VT_INT VT = 0x16
|
||||
VT_UINT VT = 0x17
|
||||
VT_VOID VT = 0x18
|
||||
VT_HRESULT VT = 0x19
|
||||
VT_PTR VT = 0x1a
|
||||
VT_SAFEARRAY VT = 0x1b
|
||||
VT_CARRAY VT = 0x1c
|
||||
VT_USERDEFINED VT = 0x1d
|
||||
VT_LPSTR VT = 0x1e
|
||||
VT_LPWSTR VT = 0x1f
|
||||
VT_RECORD VT = 0x24
|
||||
VT_INT_PTR VT = 0x25
|
||||
VT_UINT_PTR VT = 0x26
|
||||
VT_FILETIME VT = 0x40
|
||||
VT_BLOB VT = 0x41
|
||||
VT_STREAM VT = 0x42
|
||||
VT_STORAGE VT = 0x43
|
||||
VT_STREAMED_OBJECT VT = 0x44
|
||||
VT_STORED_OBJECT VT = 0x45
|
||||
VT_BLOB_OBJECT VT = 0x46
|
||||
VT_CF VT = 0x47
|
||||
VT_CLSID VT = 0x48
|
||||
VT_BSTR_BLOB VT = 0xfff
|
||||
VT_VECTOR VT = 0x1000
|
||||
VT_ARRAY VT = 0x2000
|
||||
VT_BYREF VT = 0x4000
|
||||
VT_RESERVED VT = 0x8000
|
||||
VT_ILLEGAL VT = 0xffff
|
||||
VT_ILLEGALMASKED VT = 0xfff
|
||||
VT_TYPEMASK VT = 0xfff
|
||||
)
|
||||
|
||||
const (
|
||||
DISPID_UNKNOWN = -1
|
||||
DISPID_VALUE = 0
|
||||
DISPID_PROPERTYPUT = -3
|
||||
DISPID_NEWENUM = -4
|
||||
DISPID_EVALUATE = -5
|
||||
DISPID_CONSTRUCTOR = -6
|
||||
DISPID_DESTRUCTOR = -7
|
||||
DISPID_COLLECT = -8
|
||||
)
|
||||
|
||||
const (
|
||||
TKIND_ENUM = 1
|
||||
TKIND_RECORD = 2
|
||||
TKIND_MODULE = 3
|
||||
TKIND_INTERFACE = 4
|
||||
TKIND_DISPATCH = 5
|
||||
TKIND_COCLASS = 6
|
||||
TKIND_ALIAS = 7
|
||||
TKIND_UNION = 8
|
||||
TKIND_MAX = 9
|
||||
)
|
||||
|
||||
// Safe Array Feature Flags
|
||||
|
||||
const (
|
||||
FADF_AUTO = 0x0001
|
||||
FADF_STATIC = 0x0002
|
||||
FADF_EMBEDDED = 0x0004
|
||||
FADF_FIXEDSIZE = 0x0010
|
||||
FADF_RECORD = 0x0020
|
||||
FADF_HAVEIID = 0x0040
|
||||
FADF_HAVEVARTYPE = 0x0080
|
||||
FADF_BSTR = 0x0100
|
||||
FADF_UNKNOWN = 0x0200
|
||||
FADF_DISPATCH = 0x0400
|
||||
FADF_VARIANT = 0x0800
|
||||
FADF_RESERVED = 0xF008
|
||||
)
|
51
vendor/github.com/go-ole/go-ole/error.go
generated
vendored
51
vendor/github.com/go-ole/go-ole/error.go
generated
vendored
@ -1,51 +0,0 @@
|
||||
package ole
|
||||
|
||||
// OleError stores COM errors.
|
||||
type OleError struct {
|
||||
hr uintptr
|
||||
description string
|
||||
subError error
|
||||
}
|
||||
|
||||
// NewError creates new error with HResult.
|
||||
func NewError(hr uintptr) *OleError {
|
||||
return &OleError{hr: hr}
|
||||
}
|
||||
|
||||
// NewErrorWithDescription creates new COM error with HResult and description.
|
||||
func NewErrorWithDescription(hr uintptr, description string) *OleError {
|
||||
return &OleError{hr: hr, description: description}
|
||||
}
|
||||
|
||||
// NewErrorWithSubError creates new COM error with parent error.
|
||||
func NewErrorWithSubError(hr uintptr, description string, err error) *OleError {
|
||||
return &OleError{hr: hr, description: description, subError: err}
|
||||
}
|
||||
|
||||
// Code is the HResult.
|
||||
func (v *OleError) Code() uintptr {
|
||||
return uintptr(v.hr)
|
||||
}
|
||||
|
||||
// String description, either manually set or format message with error code.
|
||||
func (v *OleError) String() string {
|
||||
if v.description != "" {
|
||||
return errstr(int(v.hr)) + " (" + v.description + ")"
|
||||
}
|
||||
return errstr(int(v.hr))
|
||||
}
|
||||
|
||||
// Error implements error interface.
|
||||
func (v *OleError) Error() string {
|
||||
return v.String()
|
||||
}
|
||||
|
||||
// Description retrieves error summary, if there is one.
|
||||
func (v *OleError) Description() string {
|
||||
return v.description
|
||||
}
|
||||
|
||||
// SubError returns parent error, if there is one.
|
||||
func (v *OleError) SubError() error {
|
||||
return v.subError
|
||||
}
|
8
vendor/github.com/go-ole/go-ole/error_func.go
generated
vendored
8
vendor/github.com/go-ole/go-ole/error_func.go
generated
vendored
@ -1,8 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
// errstr converts error code to string.
|
||||
func errstr(errno int) string {
|
||||
return ""
|
||||
}
|
24
vendor/github.com/go-ole/go-ole/error_windows.go
generated
vendored
24
vendor/github.com/go-ole/go-ole/error_windows.go
generated
vendored
@ -1,24 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
// errstr converts error code to string.
|
||||
func errstr(errno int) string {
|
||||
// ask windows for the remaining errors
|
||||
var flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
|
||||
b := make([]uint16, 300)
|
||||
n, err := syscall.FormatMessage(flags, 0, uint32(errno), 0, b, nil)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("error %d (FormatMessage failed with: %v)", errno, err)
|
||||
}
|
||||
// trim terminating \r and \n
|
||||
for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- {
|
||||
}
|
||||
return string(utf16.Decode(b[:n]))
|
||||
}
|
3
vendor/github.com/go-ole/go-ole/go.mod
generated
vendored
3
vendor/github.com/go-ole/go-ole/go.mod
generated
vendored
@ -1,3 +0,0 @@
|
||||
module github.com/go-ole/go-ole
|
||||
|
||||
go 1.12
|
284
vendor/github.com/go-ole/go-ole/guid.go
generated
vendored
284
vendor/github.com/go-ole/go-ole/guid.go
generated
vendored
@ -1,284 +0,0 @@
|
||||
package ole
|
||||
|
||||
var (
|
||||
// IID_NULL is null Interface ID, used when no other Interface ID is known.
|
||||
IID_NULL = NewGUID("{00000000-0000-0000-0000-000000000000}")
|
||||
|
||||
// IID_IUnknown is for IUnknown interfaces.
|
||||
IID_IUnknown = NewGUID("{00000000-0000-0000-C000-000000000046}")
|
||||
|
||||
// IID_IDispatch is for IDispatch interfaces.
|
||||
IID_IDispatch = NewGUID("{00020400-0000-0000-C000-000000000046}")
|
||||
|
||||
// IID_IEnumVariant is for IEnumVariant interfaces
|
||||
IID_IEnumVariant = NewGUID("{00020404-0000-0000-C000-000000000046}")
|
||||
|
||||
// IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
|
||||
IID_IConnectionPointContainer = NewGUID("{B196B284-BAB4-101A-B69C-00AA00341D07}")
|
||||
|
||||
// IID_IConnectionPoint is for IConnectionPoint interfaces.
|
||||
IID_IConnectionPoint = NewGUID("{B196B286-BAB4-101A-B69C-00AA00341D07}")
|
||||
|
||||
// IID_IInspectable is for IInspectable interfaces.
|
||||
IID_IInspectable = NewGUID("{AF86E2E0-B12D-4C6A-9C5A-D7AA65101E90}")
|
||||
|
||||
// IID_IProvideClassInfo is for IProvideClassInfo interfaces.
|
||||
IID_IProvideClassInfo = NewGUID("{B196B283-BAB4-101A-B69C-00AA00341D07}")
|
||||
)
|
||||
|
||||
// These are for testing and not part of any library.
|
||||
var (
|
||||
// IID_ICOMTestString is for ICOMTestString interfaces.
|
||||
//
|
||||
// {E0133EB4-C36F-469A-9D3D-C66B84BE19ED}
|
||||
IID_ICOMTestString = NewGUID("{E0133EB4-C36F-469A-9D3D-C66B84BE19ED}")
|
||||
|
||||
// IID_ICOMTestInt8 is for ICOMTestInt8 interfaces.
|
||||
//
|
||||
// {BEB06610-EB84-4155-AF58-E2BFF53680B4}
|
||||
IID_ICOMTestInt8 = NewGUID("{BEB06610-EB84-4155-AF58-E2BFF53680B4}")
|
||||
|
||||
// IID_ICOMTestInt16 is for ICOMTestInt16 interfaces.
|
||||
//
|
||||
// {DAA3F9FA-761E-4976-A860-8364CE55F6FC}
|
||||
IID_ICOMTestInt16 = NewGUID("{DAA3F9FA-761E-4976-A860-8364CE55F6FC}")
|
||||
|
||||
// IID_ICOMTestInt32 is for ICOMTestInt32 interfaces.
|
||||
//
|
||||
// {E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}
|
||||
IID_ICOMTestInt32 = NewGUID("{E3DEDEE7-38A2-4540-91D1-2EEF1D8891B0}")
|
||||
|
||||
// IID_ICOMTestInt64 is for ICOMTestInt64 interfaces.
|
||||
//
|
||||
// {8D437CBC-B3ED-485C-BC32-C336432A1623}
|
||||
IID_ICOMTestInt64 = NewGUID("{8D437CBC-B3ED-485C-BC32-C336432A1623}")
|
||||
|
||||
// IID_ICOMTestFloat is for ICOMTestFloat interfaces.
|
||||
//
|
||||
// {BF1ED004-EA02-456A-AA55-2AC8AC6B054C}
|
||||
IID_ICOMTestFloat = NewGUID("{BF1ED004-EA02-456A-AA55-2AC8AC6B054C}")
|
||||
|
||||
// IID_ICOMTestDouble is for ICOMTestDouble interfaces.
|
||||
//
|
||||
// {BF908A81-8687-4E93-999F-D86FAB284BA0}
|
||||
IID_ICOMTestDouble = NewGUID("{BF908A81-8687-4E93-999F-D86FAB284BA0}")
|
||||
|
||||
// IID_ICOMTestBoolean is for ICOMTestBoolean interfaces.
|
||||
//
|
||||
// {D530E7A6-4EE8-40D1-8931-3D63B8605010}
|
||||
IID_ICOMTestBoolean = NewGUID("{D530E7A6-4EE8-40D1-8931-3D63B8605010}")
|
||||
|
||||
// IID_ICOMEchoTestObject is for ICOMEchoTestObject interfaces.
|
||||
//
|
||||
// {6485B1EF-D780-4834-A4FE-1EBB51746CA3}
|
||||
IID_ICOMEchoTestObject = NewGUID("{6485B1EF-D780-4834-A4FE-1EBB51746CA3}")
|
||||
|
||||
// IID_ICOMTestTypes is for ICOMTestTypes interfaces.
|
||||
//
|
||||
// {CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}
|
||||
IID_ICOMTestTypes = NewGUID("{CCA8D7AE-91C0-4277-A8B3-FF4EDF28D3C0}")
|
||||
|
||||
// CLSID_COMEchoTestObject is for COMEchoTestObject class.
|
||||
//
|
||||
// {3C24506A-AE9E-4D50-9157-EF317281F1B0}
|
||||
CLSID_COMEchoTestObject = NewGUID("{3C24506A-AE9E-4D50-9157-EF317281F1B0}")
|
||||
|
||||
// CLSID_COMTestScalarClass is for COMTestScalarClass class.
|
||||
//
|
||||
// {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
|
||||
CLSID_COMTestScalarClass = NewGUID("{865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}")
|
||||
)
|
||||
|
||||
const hextable = "0123456789ABCDEF"
|
||||
const emptyGUID = "{00000000-0000-0000-0000-000000000000}"
|
||||
|
||||
// GUID is Windows API specific GUID type.
|
||||
//
|
||||
// This exists to match Windows GUID type for direct passing for COM.
|
||||
// Format is in xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx.
|
||||
type GUID struct {
|
||||
Data1 uint32
|
||||
Data2 uint16
|
||||
Data3 uint16
|
||||
Data4 [8]byte
|
||||
}
|
||||
|
||||
// NewGUID converts the given string into a globally unique identifier that is
|
||||
// compliant with the Windows API.
|
||||
//
|
||||
// The supplied string may be in any of these formats:
|
||||
//
|
||||
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
//
|
||||
// The conversion of the supplied string is not case-sensitive.
|
||||
func NewGUID(guid string) *GUID {
|
||||
d := []byte(guid)
|
||||
var d1, d2, d3, d4a, d4b []byte
|
||||
|
||||
switch len(d) {
|
||||
case 38:
|
||||
if d[0] != '{' || d[37] != '}' {
|
||||
return nil
|
||||
}
|
||||
d = d[1:37]
|
||||
fallthrough
|
||||
case 36:
|
||||
if d[8] != '-' || d[13] != '-' || d[18] != '-' || d[23] != '-' {
|
||||
return nil
|
||||
}
|
||||
d1 = d[0:8]
|
||||
d2 = d[9:13]
|
||||
d3 = d[14:18]
|
||||
d4a = d[19:23]
|
||||
d4b = d[24:36]
|
||||
case 32:
|
||||
d1 = d[0:8]
|
||||
d2 = d[8:12]
|
||||
d3 = d[12:16]
|
||||
d4a = d[16:20]
|
||||
d4b = d[20:32]
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
var g GUID
|
||||
var ok1, ok2, ok3, ok4 bool
|
||||
g.Data1, ok1 = decodeHexUint32(d1)
|
||||
g.Data2, ok2 = decodeHexUint16(d2)
|
||||
g.Data3, ok3 = decodeHexUint16(d3)
|
||||
g.Data4, ok4 = decodeHexByte64(d4a, d4b)
|
||||
if ok1 && ok2 && ok3 && ok4 {
|
||||
return &g
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeHexUint32(src []byte) (value uint32, ok bool) {
|
||||
var b1, b2, b3, b4 byte
|
||||
var ok1, ok2, ok3, ok4 bool
|
||||
b1, ok1 = decodeHexByte(src[0], src[1])
|
||||
b2, ok2 = decodeHexByte(src[2], src[3])
|
||||
b3, ok3 = decodeHexByte(src[4], src[5])
|
||||
b4, ok4 = decodeHexByte(src[6], src[7])
|
||||
value = (uint32(b1) << 24) | (uint32(b2) << 16) | (uint32(b3) << 8) | uint32(b4)
|
||||
ok = ok1 && ok2 && ok3 && ok4
|
||||
return
|
||||
}
|
||||
|
||||
func decodeHexUint16(src []byte) (value uint16, ok bool) {
|
||||
var b1, b2 byte
|
||||
var ok1, ok2 bool
|
||||
b1, ok1 = decodeHexByte(src[0], src[1])
|
||||
b2, ok2 = decodeHexByte(src[2], src[3])
|
||||
value = (uint16(b1) << 8) | uint16(b2)
|
||||
ok = ok1 && ok2
|
||||
return
|
||||
}
|
||||
|
||||
func decodeHexByte64(s1 []byte, s2 []byte) (value [8]byte, ok bool) {
|
||||
var ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8 bool
|
||||
value[0], ok1 = decodeHexByte(s1[0], s1[1])
|
||||
value[1], ok2 = decodeHexByte(s1[2], s1[3])
|
||||
value[2], ok3 = decodeHexByte(s2[0], s2[1])
|
||||
value[3], ok4 = decodeHexByte(s2[2], s2[3])
|
||||
value[4], ok5 = decodeHexByte(s2[4], s2[5])
|
||||
value[5], ok6 = decodeHexByte(s2[6], s2[7])
|
||||
value[6], ok7 = decodeHexByte(s2[8], s2[9])
|
||||
value[7], ok8 = decodeHexByte(s2[10], s2[11])
|
||||
ok = ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8
|
||||
return
|
||||
}
|
||||
|
||||
func decodeHexByte(c1, c2 byte) (value byte, ok bool) {
|
||||
var n1, n2 byte
|
||||
var ok1, ok2 bool
|
||||
n1, ok1 = decodeHexChar(c1)
|
||||
n2, ok2 = decodeHexChar(c2)
|
||||
value = (n1 << 4) | n2
|
||||
ok = ok1 && ok2
|
||||
return
|
||||
}
|
||||
|
||||
func decodeHexChar(c byte) (byte, bool) {
|
||||
switch {
|
||||
case '0' <= c && c <= '9':
|
||||
return c - '0', true
|
||||
case 'a' <= c && c <= 'f':
|
||||
return c - 'a' + 10, true
|
||||
case 'A' <= c && c <= 'F':
|
||||
return c - 'A' + 10, true
|
||||
}
|
||||
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// String converts the GUID to string form. It will adhere to this pattern:
|
||||
//
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
//
|
||||
// If the GUID is nil, the string representation of an empty GUID is returned:
|
||||
//
|
||||
// {00000000-0000-0000-0000-000000000000}
|
||||
func (guid *GUID) String() string {
|
||||
if guid == nil {
|
||||
return emptyGUID
|
||||
}
|
||||
|
||||
var c [38]byte
|
||||
c[0] = '{'
|
||||
putUint32Hex(c[1:9], guid.Data1)
|
||||
c[9] = '-'
|
||||
putUint16Hex(c[10:14], guid.Data2)
|
||||
c[14] = '-'
|
||||
putUint16Hex(c[15:19], guid.Data3)
|
||||
c[19] = '-'
|
||||
putByteHex(c[20:24], guid.Data4[0:2])
|
||||
c[24] = '-'
|
||||
putByteHex(c[25:37], guid.Data4[2:8])
|
||||
c[37] = '}'
|
||||
return string(c[:])
|
||||
}
|
||||
|
||||
func putUint32Hex(b []byte, v uint32) {
|
||||
b[0] = hextable[byte(v>>24)>>4]
|
||||
b[1] = hextable[byte(v>>24)&0x0f]
|
||||
b[2] = hextable[byte(v>>16)>>4]
|
||||
b[3] = hextable[byte(v>>16)&0x0f]
|
||||
b[4] = hextable[byte(v>>8)>>4]
|
||||
b[5] = hextable[byte(v>>8)&0x0f]
|
||||
b[6] = hextable[byte(v)>>4]
|
||||
b[7] = hextable[byte(v)&0x0f]
|
||||
}
|
||||
|
||||
func putUint16Hex(b []byte, v uint16) {
|
||||
b[0] = hextable[byte(v>>8)>>4]
|
||||
b[1] = hextable[byte(v>>8)&0x0f]
|
||||
b[2] = hextable[byte(v)>>4]
|
||||
b[3] = hextable[byte(v)&0x0f]
|
||||
}
|
||||
|
||||
func putByteHex(dst, src []byte) {
|
||||
for i := 0; i < len(src); i++ {
|
||||
dst[i*2] = hextable[src[i]>>4]
|
||||
dst[i*2+1] = hextable[src[i]&0x0f]
|
||||
}
|
||||
}
|
||||
|
||||
// IsEqualGUID compares two GUID.
|
||||
//
|
||||
// Not constant time comparison.
|
||||
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
|
||||
return guid1.Data1 == guid2.Data1 &&
|
||||
guid1.Data2 == guid2.Data2 &&
|
||||
guid1.Data3 == guid2.Data3 &&
|
||||
guid1.Data4[0] == guid2.Data4[0] &&
|
||||
guid1.Data4[1] == guid2.Data4[1] &&
|
||||
guid1.Data4[2] == guid2.Data4[2] &&
|
||||
guid1.Data4[3] == guid2.Data4[3] &&
|
||||
guid1.Data4[4] == guid2.Data4[4] &&
|
||||
guid1.Data4[5] == guid2.Data4[5] &&
|
||||
guid1.Data4[6] == guid2.Data4[6] &&
|
||||
guid1.Data4[7] == guid2.Data4[7]
|
||||
}
|
20
vendor/github.com/go-ole/go-ole/iconnectionpoint.go
generated
vendored
20
vendor/github.com/go-ole/go-ole/iconnectionpoint.go
generated
vendored
@ -1,20 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IConnectionPoint struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IConnectionPointVtbl struct {
|
||||
IUnknownVtbl
|
||||
GetConnectionInterface uintptr
|
||||
GetConnectionPointContainer uintptr
|
||||
Advise uintptr
|
||||
Unadvise uintptr
|
||||
EnumConnections uintptr
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) VTable() *IConnectionPointVtbl {
|
||||
return (*IConnectionPointVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
21
vendor/github.com/go-ole/go-ole/iconnectionpoint_func.go
generated
vendored
21
vendor/github.com/go-ole/go-ole/iconnectionpoint_func.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
|
||||
return int32(0)
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) Advise(unknown *IUnknown) (uint32, error) {
|
||||
return uint32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) Unadvise(cookie uint32) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) (err error) {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
43
vendor/github.com/go-ole/go-ole/iconnectionpoint_windows.go
generated
vendored
43
vendor/github.com/go-ole/go-ole/iconnectionpoint_windows.go
generated
vendored
@ -1,43 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (v *IConnectionPoint) GetConnectionInterface(piid **GUID) int32 {
|
||||
// XXX: This doesn't look like it does what it's supposed to
|
||||
return release((*IUnknown)(unsafe.Pointer(v)))
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) Advise(unknown *IUnknown) (cookie uint32, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().Advise,
|
||||
3,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(unknown)),
|
||||
uintptr(unsafe.Pointer(&cookie)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) Unadvise(cookie uint32) (err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().Unadvise,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(cookie),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IConnectionPoint) EnumConnections(p *unsafe.Pointer) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
17
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer.go
generated
vendored
17
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer.go
generated
vendored
@ -1,17 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IConnectionPointContainer struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IConnectionPointContainerVtbl struct {
|
||||
IUnknownVtbl
|
||||
EnumConnectionPoints uintptr
|
||||
FindConnectionPoint uintptr
|
||||
}
|
||||
|
||||
func (v *IConnectionPointContainer) VTable() *IConnectionPointContainerVtbl {
|
||||
return (*IConnectionPointContainerVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
11
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go
generated
vendored
11
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_func.go
generated
vendored
@ -1,11 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
25
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go
generated
vendored
25
vendor/github.com/go-ole/go-ole/iconnectionpointcontainer_windows.go
generated
vendored
@ -1,25 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (v *IConnectionPointContainer) EnumConnectionPoints(points interface{}) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IConnectionPointContainer) FindConnectionPoint(iid *GUID, point **IConnectionPoint) (err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().FindConnectionPoint,
|
||||
3,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(iid)),
|
||||
uintptr(unsafe.Pointer(point)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
94
vendor/github.com/go-ole/go-ole/idispatch.go
generated
vendored
94
vendor/github.com/go-ole/go-ole/idispatch.go
generated
vendored
@ -1,94 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IDispatch struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IDispatchVtbl struct {
|
||||
IUnknownVtbl
|
||||
GetTypeInfoCount uintptr
|
||||
GetTypeInfo uintptr
|
||||
GetIDsOfNames uintptr
|
||||
Invoke uintptr
|
||||
}
|
||||
|
||||
func (v *IDispatch) VTable() *IDispatchVtbl {
|
||||
return (*IDispatchVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
||||
|
||||
func (v *IDispatch) GetIDsOfName(names []string) (dispid []int32, err error) {
|
||||
dispid, err = getIDsOfName(v, names)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IDispatch) Invoke(dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
|
||||
result, err = invoke(v, dispid, dispatch, params...)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IDispatch) GetTypeInfoCount() (c uint32, err error) {
|
||||
c, err = getTypeInfoCount(v)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IDispatch) GetTypeInfo() (tinfo *ITypeInfo, err error) {
|
||||
tinfo, err = getTypeInfo(v)
|
||||
return
|
||||
}
|
||||
|
||||
// GetSingleIDOfName is a helper that returns single display ID for IDispatch name.
|
||||
//
|
||||
// This replaces the common pattern of attempting to get a single name from the list of available
|
||||
// IDs. It gives the first ID, if it is available.
|
||||
func (v *IDispatch) GetSingleIDOfName(name string) (displayID int32, err error) {
|
||||
var displayIDs []int32
|
||||
displayIDs, err = v.GetIDsOfName([]string{name})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
displayID = displayIDs[0]
|
||||
return
|
||||
}
|
||||
|
||||
// InvokeWithOptionalArgs accepts arguments as an array, works like Invoke.
|
||||
//
|
||||
// Accepts name and will attempt to retrieve Display ID to pass to Invoke.
|
||||
//
|
||||
// Passing params as an array is a workaround that could be fixed in later versions of Go that
|
||||
// prevent passing empty params. During testing it was discovered that this is an acceptable way of
|
||||
// getting around not being able to pass params normally.
|
||||
func (v *IDispatch) InvokeWithOptionalArgs(name string, dispatch int16, params []interface{}) (result *VARIANT, err error) {
|
||||
displayID, err := v.GetSingleIDOfName(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(params) < 1 {
|
||||
result, err = v.Invoke(displayID, dispatch)
|
||||
} else {
|
||||
result, err = v.Invoke(displayID, dispatch, params...)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CallMethod invokes named function with arguments on object.
|
||||
func (v *IDispatch) CallMethod(name string, params ...interface{}) (*VARIANT, error) {
|
||||
return v.InvokeWithOptionalArgs(name, DISPATCH_METHOD, params)
|
||||
}
|
||||
|
||||
// GetProperty retrieves the property with the name with the ability to pass arguments.
|
||||
//
|
||||
// Most of the time you will not need to pass arguments as most objects do not allow for this
|
||||
// feature. Or at least, should not allow for this feature. Some servers don't follow best practices
|
||||
// and this is provided for those edge cases.
|
||||
func (v *IDispatch) GetProperty(name string, params ...interface{}) (*VARIANT, error) {
|
||||
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYGET, params)
|
||||
}
|
||||
|
||||
// PutProperty attempts to mutate a property in the object.
|
||||
func (v *IDispatch) PutProperty(name string, params ...interface{}) (*VARIANT, error) {
|
||||
return v.InvokeWithOptionalArgs(name, DISPATCH_PROPERTYPUT, params)
|
||||
}
|
19
vendor/github.com/go-ole/go-ole/idispatch_func.go
generated
vendored
19
vendor/github.com/go-ole/go-ole/idispatch_func.go
generated
vendored
@ -1,19 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func getIDsOfName(disp *IDispatch, names []string) ([]int32, error) {
|
||||
return []int32{}, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func getTypeInfoCount(disp *IDispatch) (uint32, error) {
|
||||
return uint32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func getTypeInfo(disp *IDispatch) (*ITypeInfo, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (*VARIANT, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
200
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
200
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
@ -1,200 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func getIDsOfName(disp *IDispatch, names []string) (dispid []int32, err error) {
|
||||
wnames := make([]*uint16, len(names))
|
||||
for i := 0; i < len(names); i++ {
|
||||
wnames[i] = syscall.StringToUTF16Ptr(names[i])
|
||||
}
|
||||
dispid = make([]int32, len(names))
|
||||
namelen := uint32(len(names))
|
||||
hr, _, _ := syscall.Syscall6(
|
||||
disp.VTable().GetIDsOfNames,
|
||||
6,
|
||||
uintptr(unsafe.Pointer(disp)),
|
||||
uintptr(unsafe.Pointer(IID_NULL)),
|
||||
uintptr(unsafe.Pointer(&wnames[0])),
|
||||
uintptr(namelen),
|
||||
uintptr(GetUserDefaultLCID()),
|
||||
uintptr(unsafe.Pointer(&dispid[0])))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getTypeInfoCount(disp *IDispatch) (c uint32, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
disp.VTable().GetTypeInfoCount,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(disp)),
|
||||
uintptr(unsafe.Pointer(&c)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getTypeInfo(disp *IDispatch) (tinfo *ITypeInfo, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
disp.VTable().GetTypeInfo,
|
||||
3,
|
||||
uintptr(unsafe.Pointer(disp)),
|
||||
uintptr(GetUserDefaultLCID()),
|
||||
uintptr(unsafe.Pointer(&tinfo)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}) (result *VARIANT, err error) {
|
||||
var dispparams DISPPARAMS
|
||||
|
||||
if dispatch&DISPATCH_PROPERTYPUT != 0 {
|
||||
dispnames := [1]int32{DISPID_PROPERTYPUT}
|
||||
dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
|
||||
dispparams.cNamedArgs = 1
|
||||
} else if dispatch&DISPATCH_PROPERTYPUTREF != 0 {
|
||||
dispnames := [1]int32{DISPID_PROPERTYPUT}
|
||||
dispparams.rgdispidNamedArgs = uintptr(unsafe.Pointer(&dispnames[0]))
|
||||
dispparams.cNamedArgs = 1
|
||||
}
|
||||
var vargs []VARIANT
|
||||
if len(params) > 0 {
|
||||
vargs = make([]VARIANT, len(params))
|
||||
for i, v := range params {
|
||||
//n := len(params)-i-1
|
||||
n := len(params) - i - 1
|
||||
VariantInit(&vargs[n])
|
||||
switch vv := v.(type) {
|
||||
case bool:
|
||||
if vv {
|
||||
vargs[n] = NewVariant(VT_BOOL, 0xffff)
|
||||
} else {
|
||||
vargs[n] = NewVariant(VT_BOOL, 0)
|
||||
}
|
||||
case *bool:
|
||||
vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool)))))
|
||||
case uint8:
|
||||
vargs[n] = NewVariant(VT_I1, int64(v.(uint8)))
|
||||
case *uint8:
|
||||
vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint8)))))
|
||||
case int8:
|
||||
vargs[n] = NewVariant(VT_I1, int64(v.(int8)))
|
||||
case *int8:
|
||||
vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint8)))))
|
||||
case int16:
|
||||
vargs[n] = NewVariant(VT_I2, int64(v.(int16)))
|
||||
case *int16:
|
||||
vargs[n] = NewVariant(VT_I2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int16)))))
|
||||
case uint16:
|
||||
vargs[n] = NewVariant(VT_UI2, int64(v.(uint16)))
|
||||
case *uint16:
|
||||
vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16)))))
|
||||
case int32:
|
||||
vargs[n] = NewVariant(VT_I4, int64(v.(int32)))
|
||||
case *int32:
|
||||
vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int32)))))
|
||||
case uint32:
|
||||
vargs[n] = NewVariant(VT_UI4, int64(v.(uint32)))
|
||||
case *uint32:
|
||||
vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint32)))))
|
||||
case int64:
|
||||
vargs[n] = NewVariant(VT_I8, int64(v.(int64)))
|
||||
case *int64:
|
||||
vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64)))))
|
||||
case uint64:
|
||||
vargs[n] = NewVariant(VT_UI8, int64(uintptr(v.(uint64))))
|
||||
case *uint64:
|
||||
vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64)))))
|
||||
case int:
|
||||
vargs[n] = NewVariant(VT_I4, int64(v.(int)))
|
||||
case *int:
|
||||
vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
|
||||
case uint:
|
||||
vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
|
||||
case *uint:
|
||||
vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
|
||||
case float32:
|
||||
vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv)))
|
||||
case *float32:
|
||||
vargs[n] = NewVariant(VT_R4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float32)))))
|
||||
case float64:
|
||||
vargs[n] = NewVariant(VT_R8, *(*int64)(unsafe.Pointer(&vv)))
|
||||
case *float64:
|
||||
vargs[n] = NewVariant(VT_R8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*float64)))))
|
||||
case *big.Int:
|
||||
vargs[n] = NewVariant(VT_DECIMAL, v.(*big.Int).Int64())
|
||||
case string:
|
||||
vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(v.(string))))))
|
||||
case *string:
|
||||
vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*string)))))
|
||||
case time.Time:
|
||||
s := vv.Format("2006-01-02 15:04:05")
|
||||
vargs[n] = NewVariant(VT_BSTR, int64(uintptr(unsafe.Pointer(SysAllocStringLen(s)))))
|
||||
case *time.Time:
|
||||
s := vv.Format("2006-01-02 15:04:05")
|
||||
vargs[n] = NewVariant(VT_BSTR|VT_BYREF, int64(uintptr(unsafe.Pointer(&s))))
|
||||
case *IDispatch:
|
||||
vargs[n] = NewVariant(VT_DISPATCH, int64(uintptr(unsafe.Pointer(v.(*IDispatch)))))
|
||||
case **IDispatch:
|
||||
vargs[n] = NewVariant(VT_DISPATCH|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(**IDispatch)))))
|
||||
case nil:
|
||||
vargs[n] = NewVariant(VT_NULL, 0)
|
||||
case *VARIANT:
|
||||
vargs[n] = NewVariant(VT_VARIANT|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*VARIANT)))))
|
||||
case []byte:
|
||||
safeByteArray := safeArrayFromByteSlice(v.([]byte))
|
||||
vargs[n] = NewVariant(VT_ARRAY|VT_UI1, int64(uintptr(unsafe.Pointer(safeByteArray))))
|
||||
defer VariantClear(&vargs[n])
|
||||
case []string:
|
||||
safeByteArray := safeArrayFromStringSlice(v.([]string))
|
||||
vargs[n] = NewVariant(VT_ARRAY|VT_BSTR, int64(uintptr(unsafe.Pointer(safeByteArray))))
|
||||
defer VariantClear(&vargs[n])
|
||||
default:
|
||||
panic("unknown type")
|
||||
}
|
||||
}
|
||||
dispparams.rgvarg = uintptr(unsafe.Pointer(&vargs[0]))
|
||||
dispparams.cArgs = uint32(len(params))
|
||||
}
|
||||
|
||||
result = new(VARIANT)
|
||||
var excepInfo EXCEPINFO
|
||||
VariantInit(result)
|
||||
hr, _, _ := syscall.Syscall9(
|
||||
disp.VTable().Invoke,
|
||||
9,
|
||||
uintptr(unsafe.Pointer(disp)),
|
||||
uintptr(dispid),
|
||||
uintptr(unsafe.Pointer(IID_NULL)),
|
||||
uintptr(GetUserDefaultLCID()),
|
||||
uintptr(dispatch),
|
||||
uintptr(unsafe.Pointer(&dispparams)),
|
||||
uintptr(unsafe.Pointer(result)),
|
||||
uintptr(unsafe.Pointer(&excepInfo)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo)
|
||||
}
|
||||
for i, varg := range vargs {
|
||||
n := len(params) - i - 1
|
||||
if varg.VT == VT_BSTR && varg.Val != 0 {
|
||||
SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val)))))
|
||||
}
|
||||
if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 {
|
||||
*(params[n].(*string)) = LpOleStrToString(*(**uint16)(unsafe.Pointer(uintptr(varg.Val))))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
19
vendor/github.com/go-ole/go-ole/ienumvariant.go
generated
vendored
19
vendor/github.com/go-ole/go-ole/ienumvariant.go
generated
vendored
@ -1,19 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IEnumVARIANT struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IEnumVARIANTVtbl struct {
|
||||
IUnknownVtbl
|
||||
Next uintptr
|
||||
Skip uintptr
|
||||
Reset uintptr
|
||||
Clone uintptr
|
||||
}
|
||||
|
||||
func (v *IEnumVARIANT) VTable() *IEnumVARIANTVtbl {
|
||||
return (*IEnumVARIANTVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
19
vendor/github.com/go-ole/go-ole/ienumvariant_func.go
generated
vendored
19
vendor/github.com/go-ole/go-ole/ienumvariant_func.go
generated
vendored
@ -1,19 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func (enum *IEnumVARIANT) Clone() (*IEnumVARIANT, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Reset() error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Skip(celt uint) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Next(celt uint) (VARIANT, uint, error) {
|
||||
return NewVariant(VT_NULL, int64(0)), 0, NewError(E_NOTIMPL)
|
||||
}
|
63
vendor/github.com/go-ole/go-ole/ienumvariant_windows.go
generated
vendored
63
vendor/github.com/go-ole/go-ole/ienumvariant_windows.go
generated
vendored
@ -1,63 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (enum *IEnumVARIANT) Clone() (cloned *IEnumVARIANT, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
enum.VTable().Clone,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(enum)),
|
||||
uintptr(unsafe.Pointer(&cloned)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Reset() (err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
enum.VTable().Reset,
|
||||
1,
|
||||
uintptr(unsafe.Pointer(enum)),
|
||||
0,
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Skip(celt uint) (err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
enum.VTable().Skip,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(enum)),
|
||||
uintptr(celt),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (enum *IEnumVARIANT) Next(celt uint) (array VARIANT, length uint, err error) {
|
||||
hr, _, _ := syscall.Syscall6(
|
||||
enum.VTable().Next,
|
||||
4,
|
||||
uintptr(unsafe.Pointer(enum)),
|
||||
uintptr(celt),
|
||||
uintptr(unsafe.Pointer(&array)),
|
||||
uintptr(unsafe.Pointer(&length)),
|
||||
0,
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
18
vendor/github.com/go-ole/go-ole/iinspectable.go
generated
vendored
18
vendor/github.com/go-ole/go-ole/iinspectable.go
generated
vendored
@ -1,18 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IInspectable struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IInspectableVtbl struct {
|
||||
IUnknownVtbl
|
||||
GetIIds uintptr
|
||||
GetRuntimeClassName uintptr
|
||||
GetTrustLevel uintptr
|
||||
}
|
||||
|
||||
func (v *IInspectable) VTable() *IInspectableVtbl {
|
||||
return (*IInspectableVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
15
vendor/github.com/go-ole/go-ole/iinspectable_func.go
generated
vendored
15
vendor/github.com/go-ole/go-ole/iinspectable_func.go
generated
vendored
@ -1,15 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func (v *IInspectable) GetIids() ([]*GUID, error) {
|
||||
return []*GUID{}, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IInspectable) GetRuntimeClassName() (string, error) {
|
||||
return "", NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func (v *IInspectable) GetTrustLevel() (uint32, error) {
|
||||
return uint32(0), NewError(E_NOTIMPL)
|
||||
}
|
72
vendor/github.com/go-ole/go-ole/iinspectable_windows.go
generated
vendored
72
vendor/github.com/go-ole/go-ole/iinspectable_windows.go
generated
vendored
@ -1,72 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (v *IInspectable) GetIids() (iids []*GUID, err error) {
|
||||
var count uint32
|
||||
var array uintptr
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().GetIIds,
|
||||
3,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(&count)),
|
||||
uintptr(unsafe.Pointer(&array)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
return
|
||||
}
|
||||
defer CoTaskMemFree(array)
|
||||
|
||||
iids = make([]*GUID, count)
|
||||
byteCount := count * uint32(unsafe.Sizeof(GUID{}))
|
||||
slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)}
|
||||
byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr))
|
||||
reader := bytes.NewReader(byteSlice)
|
||||
for i := range iids {
|
||||
guid := GUID{}
|
||||
err = binary.Read(reader, binary.LittleEndian, &guid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
iids[i] = &guid
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IInspectable) GetRuntimeClassName() (s string, err error) {
|
||||
var hstring HString
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().GetRuntimeClassName,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(&hstring)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
return
|
||||
}
|
||||
s = hstring.String()
|
||||
DeleteHString(hstring)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IInspectable) GetTrustLevel() (level uint32, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
v.VTable().GetTrustLevel,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(&level)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo.go
generated
vendored
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IProvideClassInfo struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type IProvideClassInfoVtbl struct {
|
||||
IUnknownVtbl
|
||||
GetClassInfo uintptr
|
||||
}
|
||||
|
||||
func (v *IProvideClassInfo) VTable() *IProvideClassInfoVtbl {
|
||||
return (*IProvideClassInfoVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
||||
|
||||
func (v *IProvideClassInfo) GetClassInfo() (cinfo *ITypeInfo, err error) {
|
||||
cinfo, err = getClassInfo(v)
|
||||
return
|
||||
}
|
7
vendor/github.com/go-ole/go-ole/iprovideclassinfo_func.go
generated
vendored
7
vendor/github.com/go-ole/go-ole/iprovideclassinfo_func.go
generated
vendored
@ -1,7 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo_windows.go
generated
vendored
21
vendor/github.com/go-ole/go-ole/iprovideclassinfo_windows.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func getClassInfo(disp *IProvideClassInfo) (tinfo *ITypeInfo, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
disp.VTable().GetClassInfo,
|
||||
2,
|
||||
uintptr(unsafe.Pointer(disp)),
|
||||
uintptr(unsafe.Pointer(&tinfo)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
34
vendor/github.com/go-ole/go-ole/itypeinfo.go
generated
vendored
34
vendor/github.com/go-ole/go-ole/itypeinfo.go
generated
vendored
@ -1,34 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type ITypeInfo struct {
|
||||
IUnknown
|
||||
}
|
||||
|
||||
type ITypeInfoVtbl struct {
|
||||
IUnknownVtbl
|
||||
GetTypeAttr uintptr
|
||||
GetTypeComp uintptr
|
||||
GetFuncDesc uintptr
|
||||
GetVarDesc uintptr
|
||||
GetNames uintptr
|
||||
GetRefTypeOfImplType uintptr
|
||||
GetImplTypeFlags uintptr
|
||||
GetIDsOfNames uintptr
|
||||
Invoke uintptr
|
||||
GetDocumentation uintptr
|
||||
GetDllEntry uintptr
|
||||
GetRefTypeInfo uintptr
|
||||
AddressOfMember uintptr
|
||||
CreateInstance uintptr
|
||||
GetMops uintptr
|
||||
GetContainingTypeLib uintptr
|
||||
ReleaseTypeAttr uintptr
|
||||
ReleaseFuncDesc uintptr
|
||||
ReleaseVarDesc uintptr
|
||||
}
|
||||
|
||||
func (v *ITypeInfo) VTable() *ITypeInfoVtbl {
|
||||
return (*ITypeInfoVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
7
vendor/github.com/go-ole/go-ole/itypeinfo_func.go
generated
vendored
7
vendor/github.com/go-ole/go-ole/itypeinfo_func.go
generated
vendored
@ -1,7 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func (v *ITypeInfo) GetTypeAttr() (*TYPEATTR, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
21
vendor/github.com/go-ole/go-ole/itypeinfo_windows.go
generated
vendored
21
vendor/github.com/go-ole/go-ole/itypeinfo_windows.go
generated
vendored
@ -1,21 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func (v *ITypeInfo) GetTypeAttr() (tattr *TYPEATTR, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
uintptr(v.VTable().GetTypeAttr),
|
||||
2,
|
||||
uintptr(unsafe.Pointer(v)),
|
||||
uintptr(unsafe.Pointer(&tattr)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
57
vendor/github.com/go-ole/go-ole/iunknown.go
generated
vendored
57
vendor/github.com/go-ole/go-ole/iunknown.go
generated
vendored
@ -1,57 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type IUnknown struct {
|
||||
RawVTable *interface{}
|
||||
}
|
||||
|
||||
type IUnknownVtbl struct {
|
||||
QueryInterface uintptr
|
||||
AddRef uintptr
|
||||
Release uintptr
|
||||
}
|
||||
|
||||
type UnknownLike interface {
|
||||
QueryInterface(iid *GUID) (disp *IDispatch, err error)
|
||||
AddRef() int32
|
||||
Release() int32
|
||||
}
|
||||
|
||||
func (v *IUnknown) VTable() *IUnknownVtbl {
|
||||
return (*IUnknownVtbl)(unsafe.Pointer(v.RawVTable))
|
||||
}
|
||||
|
||||
func (v *IUnknown) PutQueryInterface(interfaceID *GUID, obj interface{}) error {
|
||||
return reflectQueryInterface(v, v.VTable().QueryInterface, interfaceID, obj)
|
||||
}
|
||||
|
||||
func (v *IUnknown) IDispatch(interfaceID *GUID) (dispatch *IDispatch, err error) {
|
||||
err = v.PutQueryInterface(interfaceID, &dispatch)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IUnknown) IEnumVARIANT(interfaceID *GUID) (enum *IEnumVARIANT, err error) {
|
||||
err = v.PutQueryInterface(interfaceID, &enum)
|
||||
return
|
||||
}
|
||||
|
||||
func (v *IUnknown) QueryInterface(iid *GUID) (*IDispatch, error) {
|
||||
return queryInterface(v, iid)
|
||||
}
|
||||
|
||||
func (v *IUnknown) MustQueryInterface(iid *GUID) (disp *IDispatch) {
|
||||
unk, err := queryInterface(v, iid)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return unk
|
||||
}
|
||||
|
||||
func (v *IUnknown) AddRef() int32 {
|
||||
return addRef(v)
|
||||
}
|
||||
|
||||
func (v *IUnknown) Release() int32 {
|
||||
return release(v)
|
||||
}
|
19
vendor/github.com/go-ole/go-ole/iunknown_func.go
generated
vendored
19
vendor/github.com/go-ole/go-ole/iunknown_func.go
generated
vendored
@ -1,19 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
func addRef(unk *IUnknown) int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func release(unk *IUnknown) int32 {
|
||||
return 0
|
||||
}
|
58
vendor/github.com/go-ole/go-ole/iunknown_windows.go
generated
vendored
58
vendor/github.com/go-ole/go-ole/iunknown_windows.go
generated
vendored
@ -1,58 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func reflectQueryInterface(self interface{}, method uintptr, interfaceID *GUID, obj interface{}) (err error) {
|
||||
selfValue := reflect.ValueOf(self).Elem()
|
||||
objValue := reflect.ValueOf(obj).Elem()
|
||||
|
||||
hr, _, _ := syscall.Syscall(
|
||||
method,
|
||||
3,
|
||||
selfValue.UnsafeAddr(),
|
||||
uintptr(unsafe.Pointer(interfaceID)),
|
||||
objValue.Addr().Pointer())
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func queryInterface(unk *IUnknown, iid *GUID) (disp *IDispatch, err error) {
|
||||
hr, _, _ := syscall.Syscall(
|
||||
unk.VTable().QueryInterface,
|
||||
3,
|
||||
uintptr(unsafe.Pointer(unk)),
|
||||
uintptr(unsafe.Pointer(iid)),
|
||||
uintptr(unsafe.Pointer(&disp)))
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addRef(unk *IUnknown) int32 {
|
||||
ret, _, _ := syscall.Syscall(
|
||||
unk.VTable().AddRef,
|
||||
1,
|
||||
uintptr(unsafe.Pointer(unk)),
|
||||
0,
|
||||
0)
|
||||
return int32(ret)
|
||||
}
|
||||
|
||||
func release(unk *IUnknown) int32 {
|
||||
ret, _, _ := syscall.Syscall(
|
||||
unk.VTable().Release,
|
||||
1,
|
||||
uintptr(unsafe.Pointer(unk)),
|
||||
0,
|
||||
0)
|
||||
return int32(ret)
|
||||
}
|
157
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
157
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
@ -1,157 +0,0 @@
|
||||
package ole
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DISPPARAMS are the arguments that passed to methods or property.
|
||||
type DISPPARAMS struct {
|
||||
rgvarg uintptr
|
||||
rgdispidNamedArgs uintptr
|
||||
cArgs uint32
|
||||
cNamedArgs uint32
|
||||
}
|
||||
|
||||
// EXCEPINFO defines exception info.
|
||||
type EXCEPINFO struct {
|
||||
wCode uint16
|
||||
wReserved uint16
|
||||
bstrSource *uint16
|
||||
bstrDescription *uint16
|
||||
bstrHelpFile *uint16
|
||||
dwHelpContext uint32
|
||||
pvReserved uintptr
|
||||
pfnDeferredFillIn uintptr
|
||||
scode uint32
|
||||
}
|
||||
|
||||
// WCode return wCode in EXCEPINFO.
|
||||
func (e EXCEPINFO) WCode() uint16 {
|
||||
return e.wCode
|
||||
}
|
||||
|
||||
// SCODE return scode in EXCEPINFO.
|
||||
func (e EXCEPINFO) SCODE() uint32 {
|
||||
return e.scode
|
||||
}
|
||||
|
||||
// String convert EXCEPINFO to string.
|
||||
func (e EXCEPINFO) String() string {
|
||||
var src, desc, hlp string
|
||||
if e.bstrSource == nil {
|
||||
src = "<nil>"
|
||||
} else {
|
||||
src = BstrToString(e.bstrSource)
|
||||
}
|
||||
|
||||
if e.bstrDescription == nil {
|
||||
desc = "<nil>"
|
||||
} else {
|
||||
desc = BstrToString(e.bstrDescription)
|
||||
}
|
||||
|
||||
if e.bstrHelpFile == nil {
|
||||
hlp = "<nil>"
|
||||
} else {
|
||||
hlp = BstrToString(e.bstrHelpFile)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
|
||||
e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
|
||||
)
|
||||
}
|
||||
|
||||
// Error implements error interface and returns error string.
|
||||
func (e EXCEPINFO) Error() string {
|
||||
if e.bstrDescription != nil {
|
||||
return strings.TrimSpace(BstrToString(e.bstrDescription))
|
||||
}
|
||||
|
||||
src := "Unknown"
|
||||
if e.bstrSource != nil {
|
||||
src = BstrToString(e.bstrSource)
|
||||
}
|
||||
|
||||
code := e.scode
|
||||
if e.wCode != 0 {
|
||||
code = uint32(e.wCode)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v: %#x", src, code)
|
||||
}
|
||||
|
||||
// PARAMDATA defines parameter data type.
|
||||
type PARAMDATA struct {
|
||||
Name *int16
|
||||
Vt uint16
|
||||
}
|
||||
|
||||
// METHODDATA defines method info.
|
||||
type METHODDATA struct {
|
||||
Name *uint16
|
||||
Data *PARAMDATA
|
||||
Dispid int32
|
||||
Meth uint32
|
||||
CC int32
|
||||
CArgs uint32
|
||||
Flags uint16
|
||||
VtReturn uint32
|
||||
}
|
||||
|
||||
// INTERFACEDATA defines interface info.
|
||||
type INTERFACEDATA struct {
|
||||
MethodData *METHODDATA
|
||||
CMembers uint32
|
||||
}
|
||||
|
||||
// Point is 2D vector type.
|
||||
type Point struct {
|
||||
X int32
|
||||
Y int32
|
||||
}
|
||||
|
||||
// Msg is message between processes.
|
||||
type Msg struct {
|
||||
Hwnd uint32
|
||||
Message uint32
|
||||
Wparam int32
|
||||
Lparam int32
|
||||
Time uint32
|
||||
Pt Point
|
||||
}
|
||||
|
||||
// TYPEDESC defines data type.
|
||||
type TYPEDESC struct {
|
||||
Hreftype uint32
|
||||
VT uint16
|
||||
}
|
||||
|
||||
// IDLDESC defines IDL info.
|
||||
type IDLDESC struct {
|
||||
DwReserved uint32
|
||||
WIDLFlags uint16
|
||||
}
|
||||
|
||||
// TYPEATTR defines type info.
|
||||
type TYPEATTR struct {
|
||||
Guid GUID
|
||||
Lcid uint32
|
||||
dwReserved uint32
|
||||
MemidConstructor int32
|
||||
MemidDestructor int32
|
||||
LpstrSchema *uint16
|
||||
CbSizeInstance uint32
|
||||
Typekind int32
|
||||
CFuncs uint16
|
||||
CVars uint16
|
||||
CImplTypes uint16
|
||||
CbSizeVft uint16
|
||||
CbAlignment uint16
|
||||
WTypeFlags uint16
|
||||
WMajorVerNum uint16
|
||||
WMinorVerNum uint16
|
||||
TdescAlias TYPEDESC
|
||||
IdldescType IDLDESC
|
||||
}
|
100
vendor/github.com/go-ole/go-ole/oleutil/connection.go
generated
vendored
100
vendor/github.com/go-ole/go-ole/oleutil/connection.go
generated
vendored
@ -1,100 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
ole "github.com/go-ole/go-ole"
|
||||
)
|
||||
|
||||
type stdDispatch struct {
|
||||
lpVtbl *stdDispatchVtbl
|
||||
ref int32
|
||||
iid *ole.GUID
|
||||
iface interface{}
|
||||
funcMap map[string]int32
|
||||
}
|
||||
|
||||
type stdDispatchVtbl struct {
|
||||
pQueryInterface uintptr
|
||||
pAddRef uintptr
|
||||
pRelease uintptr
|
||||
pGetTypeInfoCount uintptr
|
||||
pGetTypeInfo uintptr
|
||||
pGetIDsOfNames uintptr
|
||||
pInvoke uintptr
|
||||
}
|
||||
|
||||
func dispQueryInterface(this *ole.IUnknown, iid *ole.GUID, punk **ole.IUnknown) uint32 {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
*punk = nil
|
||||
if ole.IsEqualGUID(iid, ole.IID_IUnknown) ||
|
||||
ole.IsEqualGUID(iid, ole.IID_IDispatch) {
|
||||
dispAddRef(this)
|
||||
*punk = this
|
||||
return ole.S_OK
|
||||
}
|
||||
if ole.IsEqualGUID(iid, pthis.iid) {
|
||||
dispAddRef(this)
|
||||
*punk = this
|
||||
return ole.S_OK
|
||||
}
|
||||
return ole.E_NOINTERFACE
|
||||
}
|
||||
|
||||
func dispAddRef(this *ole.IUnknown) int32 {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
pthis.ref++
|
||||
return pthis.ref
|
||||
}
|
||||
|
||||
func dispRelease(this *ole.IUnknown) int32 {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
pthis.ref--
|
||||
return pthis.ref
|
||||
}
|
||||
|
||||
func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
names := make([]string, len(wnames))
|
||||
for i := 0; i < len(names); i++ {
|
||||
names[i] = ole.LpOleStrToString(wnames[i])
|
||||
}
|
||||
for n := 0; n < namelen; n++ {
|
||||
if id, ok := pthis.funcMap[names[n]]; ok {
|
||||
pdisp[n] = id
|
||||
}
|
||||
}
|
||||
return ole.S_OK
|
||||
}
|
||||
|
||||
func dispGetTypeInfoCount(pcount *int) uintptr {
|
||||
if pcount != nil {
|
||||
*pcount = 0
|
||||
}
|
||||
return ole.S_OK
|
||||
}
|
||||
|
||||
func dispGetTypeInfo(ptypeif *uintptr) uintptr {
|
||||
return ole.E_NOTIMPL
|
||||
}
|
||||
|
||||
func dispInvoke(this *ole.IDispatch, dispid int32, riid *ole.GUID, lcid int, flags int16, dispparams *ole.DISPPARAMS, result *ole.VARIANT, pexcepinfo *ole.EXCEPINFO, nerr *uint) uintptr {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
found := ""
|
||||
for name, id := range pthis.funcMap {
|
||||
if id == dispid {
|
||||
found = name
|
||||
}
|
||||
}
|
||||
if found != "" {
|
||||
rv := reflect.ValueOf(pthis.iface).Elem()
|
||||
rm := rv.MethodByName(found)
|
||||
rr := rm.Call([]reflect.Value{})
|
||||
println(len(rr))
|
||||
return ole.S_OK
|
||||
}
|
||||
return ole.E_NOTIMPL
|
||||
}
|
10
vendor/github.com/go-ole/go-ole/oleutil/connection_func.go
generated
vendored
10
vendor/github.com/go-ole/go-ole/oleutil/connection_func.go
generated
vendored
@ -1,10 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import ole "github.com/go-ole/go-ole"
|
||||
|
||||
// ConnectObject creates a connection point between two services for communication.
|
||||
func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (uint32, error) {
|
||||
return 0, ole.NewError(ole.E_NOTIMPL)
|
||||
}
|
58
vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go
generated
vendored
58
vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go
generated
vendored
@ -1,58 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
ole "github.com/go-ole/go-ole"
|
||||
)
|
||||
|
||||
// ConnectObject creates a connection point between two services for communication.
|
||||
func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cookie uint32, err error) {
|
||||
unknown, err := disp.QueryInterface(ole.IID_IConnectionPointContainer)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
container := (*ole.IConnectionPointContainer)(unsafe.Pointer(unknown))
|
||||
var point *ole.IConnectionPoint
|
||||
err = container.FindConnectionPoint(iid, &point)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if edisp, ok := idisp.(*ole.IUnknown); ok {
|
||||
cookie, err = point.Advise(edisp)
|
||||
container.Release()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
rv := reflect.ValueOf(disp).Elem()
|
||||
if rv.Type().Kind() == reflect.Struct {
|
||||
dest := &stdDispatch{}
|
||||
dest.lpVtbl = &stdDispatchVtbl{}
|
||||
dest.lpVtbl.pQueryInterface = syscall.NewCallback(dispQueryInterface)
|
||||
dest.lpVtbl.pAddRef = syscall.NewCallback(dispAddRef)
|
||||
dest.lpVtbl.pRelease = syscall.NewCallback(dispRelease)
|
||||
dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(dispGetTypeInfoCount)
|
||||
dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(dispGetTypeInfo)
|
||||
dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(dispGetIDsOfNames)
|
||||
dest.lpVtbl.pInvoke = syscall.NewCallback(dispInvoke)
|
||||
dest.iface = disp
|
||||
dest.iid = iid
|
||||
cookie, err = point.Advise((*ole.IUnknown)(unsafe.Pointer(dest)))
|
||||
container.Release()
|
||||
if err != nil {
|
||||
point.Release()
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
container.Release()
|
||||
|
||||
return 0, ole.NewError(ole.E_INVALIDARG)
|
||||
}
|
6
vendor/github.com/go-ole/go-ole/oleutil/go-get.go
generated
vendored
6
vendor/github.com/go-ole/go-ole/oleutil/go-get.go
generated
vendored
@ -1,6 +0,0 @@
|
||||
// This file is here so go get succeeds as without it errors with:
|
||||
// no buildable Go source files in ...
|
||||
//
|
||||
// +build !windows
|
||||
|
||||
package oleutil
|
127
vendor/github.com/go-ole/go-ole/oleutil/oleutil.go
generated
vendored
127
vendor/github.com/go-ole/go-ole/oleutil/oleutil.go
generated
vendored
@ -1,127 +0,0 @@
|
||||
package oleutil
|
||||
|
||||
import ole "github.com/go-ole/go-ole"
|
||||
|
||||
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
||||
func ClassIDFrom(programID string) (classID *ole.GUID, err error) {
|
||||
return ole.ClassIDFrom(programID)
|
||||
}
|
||||
|
||||
// CreateObject creates object from programID based on interface type.
|
||||
//
|
||||
// Only supports IUnknown.
|
||||
//
|
||||
// Program ID can be either program ID or application string.
|
||||
func CreateObject(programID string) (unknown *ole.IUnknown, err error) {
|
||||
classID, err := ole.ClassIDFrom(programID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
unknown, err = ole.CreateInstance(classID, ole.IID_IUnknown)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetActiveObject retrieves active object for program ID and interface ID based
|
||||
// on interface type.
|
||||
//
|
||||
// Only supports IUnknown.
|
||||
//
|
||||
// Program ID can be either program ID or application string.
|
||||
func GetActiveObject(programID string) (unknown *ole.IUnknown, err error) {
|
||||
classID, err := ole.ClassIDFrom(programID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
unknown, err = ole.GetActiveObject(classID, ole.IID_IUnknown)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CallMethod calls method on IDispatch with parameters.
|
||||
func CallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_METHOD, params)
|
||||
}
|
||||
|
||||
// MustCallMethod calls method on IDispatch with parameters or panics.
|
||||
func MustCallMethod(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||
r, err := CallMethod(disp, name, params...)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// GetProperty retrieves property from IDispatch.
|
||||
func GetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYGET, params)
|
||||
}
|
||||
|
||||
// MustGetProperty retrieves property from IDispatch or panics.
|
||||
func MustGetProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||
r, err := GetProperty(disp, name, params...)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// PutProperty mutates property.
|
||||
func PutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUT, params)
|
||||
}
|
||||
|
||||
// MustPutProperty mutates property or panics.
|
||||
func MustPutProperty(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||
r, err := PutProperty(disp, name, params...)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// PutPropertyRef mutates property reference.
|
||||
func PutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT, err error) {
|
||||
return disp.InvokeWithOptionalArgs(name, ole.DISPATCH_PROPERTYPUTREF, params)
|
||||
}
|
||||
|
||||
// MustPutPropertyRef mutates property reference or panics.
|
||||
func MustPutPropertyRef(disp *ole.IDispatch, name string, params ...interface{}) (result *ole.VARIANT) {
|
||||
r, err := PutPropertyRef(disp, name, params...)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func ForEach(disp *ole.IDispatch, f func(v *ole.VARIANT) error) error {
|
||||
newEnum, err := disp.GetProperty("_NewEnum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer newEnum.Clear()
|
||||
|
||||
enum, err := newEnum.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer enum.Release()
|
||||
|
||||
for item, length, err := enum.Next(1); length > 0; item, length, err = enum.Next(1) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ferr := f(&item); ferr != nil {
|
||||
return ferr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
27
vendor/github.com/go-ole/go-ole/safearray.go
generated
vendored
27
vendor/github.com/go-ole/go-ole/safearray.go
generated
vendored
@ -1,27 +0,0 @@
|
||||
// Package is meant to retrieve and process safe array data returned from COM.
|
||||
|
||||
package ole
|
||||
|
||||
// SafeArrayBound defines the SafeArray boundaries.
|
||||
type SafeArrayBound struct {
|
||||
Elements uint32
|
||||
LowerBound int32
|
||||
}
|
||||
|
||||
// SafeArray is how COM handles arrays.
|
||||
type SafeArray struct {
|
||||
Dimensions uint16
|
||||
FeaturesFlag uint16
|
||||
ElementsSize uint32
|
||||
LocksAmount uint32
|
||||
Data uint32
|
||||
Bounds [16]byte
|
||||
}
|
||||
|
||||
// SAFEARRAY is obsolete, exists for backwards compatibility.
|
||||
// Use SafeArray
|
||||
type SAFEARRAY SafeArray
|
||||
|
||||
// SAFEARRAYBOUND is obsolete, exists for backwards compatibility.
|
||||
// Use SafeArrayBound
|
||||
type SAFEARRAYBOUND SafeArrayBound
|
211
vendor/github.com/go-ole/go-ole/safearray_func.go
generated
vendored
211
vendor/github.com/go-ole/go-ole/safearray_func.go
generated
vendored
@ -1,211 +0,0 @@
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// safeArrayAccessData returns raw array pointer.
|
||||
//
|
||||
// AKA: SafeArrayAccessData in Windows API.
|
||||
func safeArrayAccessData(safearray *SafeArray) (uintptr, error) {
|
||||
return uintptr(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayUnaccessData releases raw array.
|
||||
//
|
||||
// AKA: SafeArrayUnaccessData in Windows API.
|
||||
func safeArrayUnaccessData(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayAllocData allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocData in Windows API.
|
||||
func safeArrayAllocData(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayAllocDescriptor allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocDescriptor in Windows API.
|
||||
func safeArrayAllocDescriptor(dimensions uint32) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayAllocDescriptorEx allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocDescriptorEx in Windows API.
|
||||
func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCopy returns copy of SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCopy in Windows API.
|
||||
func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayCopyData in Windows API.
|
||||
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCreate creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreate in Windows API.
|
||||
func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCreateEx creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateEx in Windows API.
|
||||
func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCreateVector creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateVector in Windows API.
|
||||
func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayCreateVectorEx creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateVectorEx in Windows API.
|
||||
func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (*SafeArray, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayDestroy destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroy in Windows API.
|
||||
func safeArrayDestroy(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayDestroyData destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroyData in Windows API.
|
||||
func safeArrayDestroyData(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayDestroyDescriptor destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroyDescriptor in Windows API.
|
||||
func safeArrayDestroyDescriptor(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetDim is the amount of dimensions in the SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetDim in Windows API.
|
||||
func safeArrayGetDim(safearray *SafeArray) (*uint32, error) {
|
||||
u := uint32(0)
|
||||
return &u, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetElementSize is the element size in bytes.
|
||||
//
|
||||
// AKA: SafeArrayGetElemsize in Windows API.
|
||||
func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) {
|
||||
u := uint32(0)
|
||||
return &u, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetElement retrieves element at given index.
|
||||
func safeArrayGetElement(safearray *SafeArray, index int32, pv unsafe.Pointer) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetElement retrieves element at given index and converts to string.
|
||||
func safeArrayGetElementString(safearray *SafeArray, index int32) (string, error) {
|
||||
return "", NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayGetIID in Windows API.
|
||||
func safeArrayGetIID(safearray *SafeArray) (*GUID, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetLBound returns lower bounds of SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetLBound in Windows API.
|
||||
func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (int32, error) {
|
||||
return int32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetUBound returns upper bounds of SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetUBound in Windows API.
|
||||
func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (int32, error) {
|
||||
return int32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetVartype returns data type of SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayGetVartype in Windows API.
|
||||
func safeArrayGetVartype(safearray *SafeArray) (uint16, error) {
|
||||
return uint16(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayLock locks SafeArray for reading to modify SafeArray.
|
||||
//
|
||||
// This must be called during some calls to ensure that another process does not
|
||||
// read or write to the SafeArray during editing.
|
||||
//
|
||||
// AKA: SafeArrayLock in Windows API.
|
||||
func safeArrayLock(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayUnlock unlocks SafeArray for reading.
|
||||
//
|
||||
// AKA: SafeArrayUnlock in Windows API.
|
||||
func safeArrayUnlock(safearray *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayPutElement stores the data element at the specified location in the
|
||||
// array.
|
||||
//
|
||||
// AKA: SafeArrayPutElement in Windows API.
|
||||
func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
|
||||
//
|
||||
// AKA: SafeArrayGetRecordInfo in Windows API.
|
||||
//
|
||||
// XXX: Must implement IRecordInfo interface for this to return.
|
||||
func safeArrayGetRecordInfo(safearray *SafeArray) (interface{}, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
|
||||
//
|
||||
// AKA: SafeArraySetRecordInfo in Windows API.
|
||||
//
|
||||
// XXX: Must implement IRecordInfo interface for this to return.
|
||||
func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
337
vendor/github.com/go-ole/go-ole/safearray_windows.go
generated
vendored
337
vendor/github.com/go-ole/go-ole/safearray_windows.go
generated
vendored
@ -1,337 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
procSafeArrayAccessData, _ = modoleaut32.FindProc("SafeArrayAccessData")
|
||||
procSafeArrayAllocData, _ = modoleaut32.FindProc("SafeArrayAllocData")
|
||||
procSafeArrayAllocDescriptor, _ = modoleaut32.FindProc("SafeArrayAllocDescriptor")
|
||||
procSafeArrayAllocDescriptorEx, _ = modoleaut32.FindProc("SafeArrayAllocDescriptorEx")
|
||||
procSafeArrayCopy, _ = modoleaut32.FindProc("SafeArrayCopy")
|
||||
procSafeArrayCopyData, _ = modoleaut32.FindProc("SafeArrayCopyData")
|
||||
procSafeArrayCreate, _ = modoleaut32.FindProc("SafeArrayCreate")
|
||||
procSafeArrayCreateEx, _ = modoleaut32.FindProc("SafeArrayCreateEx")
|
||||
procSafeArrayCreateVector, _ = modoleaut32.FindProc("SafeArrayCreateVector")
|
||||
procSafeArrayCreateVectorEx, _ = modoleaut32.FindProc("SafeArrayCreateVectorEx")
|
||||
procSafeArrayDestroy, _ = modoleaut32.FindProc("SafeArrayDestroy")
|
||||
procSafeArrayDestroyData, _ = modoleaut32.FindProc("SafeArrayDestroyData")
|
||||
procSafeArrayDestroyDescriptor, _ = modoleaut32.FindProc("SafeArrayDestroyDescriptor")
|
||||
procSafeArrayGetDim, _ = modoleaut32.FindProc("SafeArrayGetDim")
|
||||
procSafeArrayGetElement, _ = modoleaut32.FindProc("SafeArrayGetElement")
|
||||
procSafeArrayGetElemsize, _ = modoleaut32.FindProc("SafeArrayGetElemsize")
|
||||
procSafeArrayGetIID, _ = modoleaut32.FindProc("SafeArrayGetIID")
|
||||
procSafeArrayGetLBound, _ = modoleaut32.FindProc("SafeArrayGetLBound")
|
||||
procSafeArrayGetUBound, _ = modoleaut32.FindProc("SafeArrayGetUBound")
|
||||
procSafeArrayGetVartype, _ = modoleaut32.FindProc("SafeArrayGetVartype")
|
||||
procSafeArrayLock, _ = modoleaut32.FindProc("SafeArrayLock")
|
||||
procSafeArrayPtrOfIndex, _ = modoleaut32.FindProc("SafeArrayPtrOfIndex")
|
||||
procSafeArrayUnaccessData, _ = modoleaut32.FindProc("SafeArrayUnaccessData")
|
||||
procSafeArrayUnlock, _ = modoleaut32.FindProc("SafeArrayUnlock")
|
||||
procSafeArrayPutElement, _ = modoleaut32.FindProc("SafeArrayPutElement")
|
||||
//procSafeArrayRedim, _ = modoleaut32.FindProc("SafeArrayRedim") // TODO
|
||||
//procSafeArraySetIID, _ = modoleaut32.FindProc("SafeArraySetIID") // TODO
|
||||
procSafeArrayGetRecordInfo, _ = modoleaut32.FindProc("SafeArrayGetRecordInfo")
|
||||
procSafeArraySetRecordInfo, _ = modoleaut32.FindProc("SafeArraySetRecordInfo")
|
||||
)
|
||||
|
||||
// safeArrayAccessData returns raw array pointer.
|
||||
//
|
||||
// AKA: SafeArrayAccessData in Windows API.
|
||||
// Todo: Test
|
||||
func safeArrayAccessData(safearray *SafeArray) (element uintptr, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayAccessData.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&element))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayUnaccessData releases raw array.
|
||||
//
|
||||
// AKA: SafeArrayUnaccessData in Windows API.
|
||||
func safeArrayUnaccessData(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayUnaccessData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayAllocData allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocData in Windows API.
|
||||
func safeArrayAllocData(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayAllocData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayAllocDescriptor allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocDescriptor in Windows API.
|
||||
func safeArrayAllocDescriptor(dimensions uint32) (safearray *SafeArray, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayAllocDescriptor.Call(uintptr(dimensions), uintptr(unsafe.Pointer(&safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayAllocDescriptorEx allocates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayAllocDescriptorEx in Windows API.
|
||||
func safeArrayAllocDescriptorEx(variantType VT, dimensions uint32) (safearray *SafeArray, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayAllocDescriptorEx.Call(
|
||||
uintptr(variantType),
|
||||
uintptr(dimensions),
|
||||
uintptr(unsafe.Pointer(&safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCopy returns copy of SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCopy in Windows API.
|
||||
func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayCopy.Call(
|
||||
uintptr(unsafe.Pointer(original)),
|
||||
uintptr(unsafe.Pointer(&safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayCopyData in Windows API.
|
||||
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayCopyData.Call(
|
||||
uintptr(unsafe.Pointer(original)),
|
||||
uintptr(unsafe.Pointer(duplicate))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCreate creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreate in Windows API.
|
||||
func safeArrayCreate(variantType VT, dimensions uint32, bounds *SafeArrayBound) (safearray *SafeArray, err error) {
|
||||
sa, _, err := procSafeArrayCreate.Call(
|
||||
uintptr(variantType),
|
||||
uintptr(dimensions),
|
||||
uintptr(unsafe.Pointer(bounds)))
|
||||
safearray = (*SafeArray)(unsafe.Pointer(&sa))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCreateEx creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateEx in Windows API.
|
||||
func safeArrayCreateEx(variantType VT, dimensions uint32, bounds *SafeArrayBound, extra uintptr) (safearray *SafeArray, err error) {
|
||||
sa, _, err := procSafeArrayCreateEx.Call(
|
||||
uintptr(variantType),
|
||||
uintptr(dimensions),
|
||||
uintptr(unsafe.Pointer(bounds)),
|
||||
extra)
|
||||
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCreateVector creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateVector in Windows API.
|
||||
func safeArrayCreateVector(variantType VT, lowerBound int32, length uint32) (safearray *SafeArray, err error) {
|
||||
sa, _, err := procSafeArrayCreateVector.Call(
|
||||
uintptr(variantType),
|
||||
uintptr(lowerBound),
|
||||
uintptr(length))
|
||||
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayCreateVectorEx creates SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayCreateVectorEx in Windows API.
|
||||
func safeArrayCreateVectorEx(variantType VT, lowerBound int32, length uint32, extra uintptr) (safearray *SafeArray, err error) {
|
||||
sa, _, err := procSafeArrayCreateVectorEx.Call(
|
||||
uintptr(variantType),
|
||||
uintptr(lowerBound),
|
||||
uintptr(length),
|
||||
extra)
|
||||
safearray = (*SafeArray)(unsafe.Pointer(sa))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayDestroy destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroy in Windows API.
|
||||
func safeArrayDestroy(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayDestroy.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayDestroyData destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroyData in Windows API.
|
||||
func safeArrayDestroyData(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayDestroyData.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayDestroyDescriptor destroys SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayDestroyDescriptor in Windows API.
|
||||
func safeArrayDestroyDescriptor(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayDestroyDescriptor.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetDim is the amount of dimensions in the SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetDim in Windows API.
|
||||
func safeArrayGetDim(safearray *SafeArray) (dimensions *uint32, err error) {
|
||||
l, _, err := procSafeArrayGetDim.Call(uintptr(unsafe.Pointer(safearray)))
|
||||
dimensions = (*uint32)(unsafe.Pointer(l))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetElementSize is the element size in bytes.
|
||||
//
|
||||
// AKA: SafeArrayGetElemsize in Windows API.
|
||||
func safeArrayGetElementSize(safearray *SafeArray) (length *uint32, err error) {
|
||||
l, _, err := procSafeArrayGetElemsize.Call(uintptr(unsafe.Pointer(safearray)))
|
||||
length = (*uint32)(unsafe.Pointer(l))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetElement retrieves element at given index.
|
||||
func safeArrayGetElement(safearray *SafeArray, index int32, pv unsafe.Pointer) error {
|
||||
return convertHresultToError(
|
||||
procSafeArrayGetElement.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&index)),
|
||||
uintptr(pv)))
|
||||
}
|
||||
|
||||
// safeArrayGetElementString retrieves element at given index and converts to string.
|
||||
func safeArrayGetElementString(safearray *SafeArray, index int32) (str string, err error) {
|
||||
var element *int16
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetElement.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&index)),
|
||||
uintptr(unsafe.Pointer(&element))))
|
||||
str = BstrToString(*(**uint16)(unsafe.Pointer(&element)))
|
||||
SysFreeString(element)
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetIID is the InterfaceID of the elements in the SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayGetIID in Windows API.
|
||||
func safeArrayGetIID(safearray *SafeArray) (guid *GUID, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetIID.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&guid))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetLBound returns lower bounds of SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetLBound in Windows API.
|
||||
func safeArrayGetLBound(safearray *SafeArray, dimension uint32) (lowerBound int32, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetLBound.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(dimension),
|
||||
uintptr(unsafe.Pointer(&lowerBound))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetUBound returns upper bounds of SafeArray.
|
||||
//
|
||||
// SafeArrays may have multiple dimensions. Meaning, it could be
|
||||
// multidimensional array.
|
||||
//
|
||||
// AKA: SafeArrayGetUBound in Windows API.
|
||||
func safeArrayGetUBound(safearray *SafeArray, dimension uint32) (upperBound int32, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetUBound.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(dimension),
|
||||
uintptr(unsafe.Pointer(&upperBound))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetVartype returns data type of SafeArray.
|
||||
//
|
||||
// AKA: SafeArrayGetVartype in Windows API.
|
||||
func safeArrayGetVartype(safearray *SafeArray) (varType uint16, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetVartype.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&varType))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayLock locks SafeArray for reading to modify SafeArray.
|
||||
//
|
||||
// This must be called during some calls to ensure that another process does not
|
||||
// read or write to the SafeArray during editing.
|
||||
//
|
||||
// AKA: SafeArrayLock in Windows API.
|
||||
func safeArrayLock(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayLock.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayUnlock unlocks SafeArray for reading.
|
||||
//
|
||||
// AKA: SafeArrayUnlock in Windows API.
|
||||
func safeArrayUnlock(safearray *SafeArray) (err error) {
|
||||
err = convertHresultToError(procSafeArrayUnlock.Call(uintptr(unsafe.Pointer(safearray))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayPutElement stores the data element at the specified location in the
|
||||
// array.
|
||||
//
|
||||
// AKA: SafeArrayPutElement in Windows API.
|
||||
func safeArrayPutElement(safearray *SafeArray, index int64, element uintptr) (err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayPutElement.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&index)),
|
||||
uintptr(unsafe.Pointer(element))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArrayGetRecordInfo accesses IRecordInfo info for custom types.
|
||||
//
|
||||
// AKA: SafeArrayGetRecordInfo in Windows API.
|
||||
//
|
||||
// XXX: Must implement IRecordInfo interface for this to return.
|
||||
func safeArrayGetRecordInfo(safearray *SafeArray) (recordInfo interface{}, err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayGetRecordInfo.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&recordInfo))))
|
||||
return
|
||||
}
|
||||
|
||||
// safeArraySetRecordInfo mutates IRecordInfo info for custom types.
|
||||
//
|
||||
// AKA: SafeArraySetRecordInfo in Windows API.
|
||||
//
|
||||
// XXX: Must implement IRecordInfo interface for this to return.
|
||||
func safeArraySetRecordInfo(safearray *SafeArray, recordInfo interface{}) (err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArraySetRecordInfo.Call(
|
||||
uintptr(unsafe.Pointer(safearray)),
|
||||
uintptr(unsafe.Pointer(&recordInfo))))
|
||||
return
|
||||
}
|
140
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
140
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
@ -1,140 +0,0 @@
|
||||
// Helper for converting SafeArray to array of objects.
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type SafeArrayConversion struct {
|
||||
Array *SafeArray
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) ToStringArray() (strings []string) {
|
||||
totalElements, _ := sac.TotalElements(0)
|
||||
strings = make([]string, totalElements)
|
||||
|
||||
for i := int32(0); i < totalElements; i++ {
|
||||
strings[int32(i)], _ = safeArrayGetElementString(sac.Array, i)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) ToByteArray() (bytes []byte) {
|
||||
totalElements, _ := sac.TotalElements(0)
|
||||
bytes = make([]byte, totalElements)
|
||||
|
||||
for i := int32(0); i < totalElements; i++ {
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&bytes[int32(i)]))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) ToValueArray() (values []interface{}) {
|
||||
totalElements, _ := sac.TotalElements(0)
|
||||
values = make([]interface{}, totalElements)
|
||||
vt, _ := safeArrayGetVartype(sac.Array)
|
||||
|
||||
for i := int32(0); i < totalElements; i++ {
|
||||
switch VT(vt) {
|
||||
case VT_BOOL:
|
||||
var v bool
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_I1:
|
||||
var v int8
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_I2:
|
||||
var v int16
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_I4:
|
||||
var v int32
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_I8:
|
||||
var v int64
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_UI1:
|
||||
var v uint8
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_UI2:
|
||||
var v uint16
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_UI4:
|
||||
var v uint32
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_UI8:
|
||||
var v uint64
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_R4:
|
||||
var v float32
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_R8:
|
||||
var v float64
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_BSTR:
|
||||
var v string
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_VARIANT:
|
||||
var v VARIANT
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v.Value()
|
||||
default:
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) GetType() (varType uint16, err error) {
|
||||
return safeArrayGetVartype(sac.Array)
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) GetDimensions() (dimensions *uint32, err error) {
|
||||
return safeArrayGetDim(sac.Array)
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) GetSize() (length *uint32, err error) {
|
||||
return safeArrayGetElementSize(sac.Array)
|
||||
}
|
||||
|
||||
func (sac *SafeArrayConversion) TotalElements(index uint32) (totalElements int32, err error) {
|
||||
if index < 1 {
|
||||
index = 1
|
||||
}
|
||||
|
||||
// Get array bounds
|
||||
var LowerBounds int32
|
||||
var UpperBounds int32
|
||||
|
||||
LowerBounds, err = safeArrayGetLBound(sac.Array, index)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
UpperBounds, err = safeArrayGetUBound(sac.Array, index)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
totalElements = UpperBounds - LowerBounds + 1
|
||||
return
|
||||
}
|
||||
|
||||
// Release Safe Array memory
|
||||
func (sac *SafeArrayConversion) Release() {
|
||||
safeArrayDestroy(sac.Array)
|
||||
}
|
33
vendor/github.com/go-ole/go-ole/safearrayslices.go
generated
vendored
33
vendor/github.com/go-ole/go-ole/safearrayslices.go
generated
vendored
@ -1,33 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func safeArrayFromByteSlice(slice []byte) *SafeArray {
|
||||
array, _ := safeArrayCreateVector(VT_UI1, 0, uint32(len(slice)))
|
||||
|
||||
if array == nil {
|
||||
panic("Could not convert []byte to SAFEARRAY")
|
||||
}
|
||||
|
||||
for i, v := range slice {
|
||||
safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(&v)))
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
func safeArrayFromStringSlice(slice []string) *SafeArray {
|
||||
array, _ := safeArrayCreateVector(VT_BSTR, 0, uint32(len(slice)))
|
||||
|
||||
if array == nil {
|
||||
panic("Could not convert []string to SAFEARRAY")
|
||||
}
|
||||
// SysAllocStringLen(s)
|
||||
for i, v := range slice {
|
||||
safeArrayPutElement(array, int64(i), uintptr(unsafe.Pointer(SysAllocStringLen(v))))
|
||||
}
|
||||
return array
|
||||
}
|
101
vendor/github.com/go-ole/go-ole/utility.go
generated
vendored
101
vendor/github.com/go-ole/go-ole/utility.go
generated
vendored
@ -1,101 +0,0 @@
|
||||
package ole
|
||||
|
||||
import (
|
||||
"unicode/utf16"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// ClassIDFrom retrieves class ID whether given is program ID or application string.
|
||||
//
|
||||
// Helper that provides check against both Class ID from Program ID and Class ID from string. It is
|
||||
// faster, if you know which you are using, to use the individual functions, but this will check
|
||||
// against available functions for you.
|
||||
func ClassIDFrom(programID string) (classID *GUID, err error) {
|
||||
classID, err = CLSIDFromProgID(programID)
|
||||
if err != nil {
|
||||
classID, err = CLSIDFromString(programID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BytePtrToString converts byte pointer to a Go string.
|
||||
func BytePtrToString(p *byte) string {
|
||||
a := (*[10000]uint8)(unsafe.Pointer(p))
|
||||
i := 0
|
||||
for a[i] != 0 {
|
||||
i++
|
||||
}
|
||||
return string(a[:i])
|
||||
}
|
||||
|
||||
// UTF16PtrToString is alias for LpOleStrToString.
|
||||
//
|
||||
// Kept for compatibility reasons.
|
||||
func UTF16PtrToString(p *uint16) string {
|
||||
return LpOleStrToString(p)
|
||||
}
|
||||
|
||||
// LpOleStrToString converts COM Unicode to Go string.
|
||||
func LpOleStrToString(p *uint16) string {
|
||||
if p == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
length := lpOleStrLen(p)
|
||||
a := make([]uint16, length)
|
||||
|
||||
ptr := unsafe.Pointer(p)
|
||||
|
||||
for i := 0; i < int(length); i++ {
|
||||
a[i] = *(*uint16)(ptr)
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||
}
|
||||
|
||||
return string(utf16.Decode(a))
|
||||
}
|
||||
|
||||
// BstrToString converts COM binary string to Go string.
|
||||
func BstrToString(p *uint16) string {
|
||||
if p == nil {
|
||||
return ""
|
||||
}
|
||||
length := SysStringLen((*int16)(unsafe.Pointer(p)))
|
||||
a := make([]uint16, length)
|
||||
|
||||
ptr := unsafe.Pointer(p)
|
||||
|
||||
for i := 0; i < int(length); i++ {
|
||||
a[i] = *(*uint16)(ptr)
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||
}
|
||||
return string(utf16.Decode(a))
|
||||
}
|
||||
|
||||
// lpOleStrLen returns the length of Unicode string.
|
||||
func lpOleStrLen(p *uint16) (length int64) {
|
||||
if p == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
ptr := unsafe.Pointer(p)
|
||||
|
||||
for i := 0; ; i++ {
|
||||
if 0 == *(*uint16)(ptr) {
|
||||
length = int64(i)
|
||||
break
|
||||
}
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 2)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// convertHresultToError converts syscall to error, if call is unsuccessful.
|
||||
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
return
|
||||
}
|
16
vendor/github.com/go-ole/go-ole/variables.go
generated
vendored
16
vendor/github.com/go-ole/go-ole/variables.go
generated
vendored
@ -1,16 +0,0 @@
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
modcombase = syscall.NewLazyDLL("combase.dll")
|
||||
modkernel32, _ = syscall.LoadDLL("kernel32.dll")
|
||||
modole32, _ = syscall.LoadDLL("ole32.dll")
|
||||
modoleaut32, _ = syscall.LoadDLL("oleaut32.dll")
|
||||
modmsvcrt, _ = syscall.LoadDLL("msvcrt.dll")
|
||||
moduser32, _ = syscall.LoadDLL("user32.dll")
|
||||
)
|
105
vendor/github.com/go-ole/go-ole/variant.go
generated
vendored
105
vendor/github.com/go-ole/go-ole/variant.go
generated
vendored
@ -1,105 +0,0 @@
|
||||
package ole
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// NewVariant returns new variant based on type and value.
|
||||
func NewVariant(vt VT, val int64) VARIANT {
|
||||
return VARIANT{VT: vt, Val: val}
|
||||
}
|
||||
|
||||
// ToIUnknown converts Variant to Unknown object.
|
||||
func (v *VARIANT) ToIUnknown() *IUnknown {
|
||||
if v.VT != VT_UNKNOWN {
|
||||
return nil
|
||||
}
|
||||
return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
|
||||
}
|
||||
|
||||
// ToIDispatch converts variant to dispatch object.
|
||||
func (v *VARIANT) ToIDispatch() *IDispatch {
|
||||
if v.VT != VT_DISPATCH {
|
||||
return nil
|
||||
}
|
||||
return (*IDispatch)(unsafe.Pointer(uintptr(v.Val)))
|
||||
}
|
||||
|
||||
// ToArray converts variant to SafeArray helper.
|
||||
func (v *VARIANT) ToArray() *SafeArrayConversion {
|
||||
if v.VT != VT_SAFEARRAY {
|
||||
if v.VT&VT_ARRAY == 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
var safeArray *SafeArray = (*SafeArray)(unsafe.Pointer(uintptr(v.Val)))
|
||||
return &SafeArrayConversion{safeArray}
|
||||
}
|
||||
|
||||
// ToString converts variant to Go string.
|
||||
func (v *VARIANT) ToString() string {
|
||||
if v.VT != VT_BSTR {
|
||||
return ""
|
||||
}
|
||||
return BstrToString(*(**uint16)(unsafe.Pointer(&v.Val)))
|
||||
}
|
||||
|
||||
// Clear the memory of variant object.
|
||||
func (v *VARIANT) Clear() error {
|
||||
return VariantClear(v)
|
||||
}
|
||||
|
||||
// Value returns variant value based on its type.
|
||||
//
|
||||
// Currently supported types: 2- and 4-byte integers, strings, bools.
|
||||
// Note that 64-bit integers, datetimes, and other types are stored as strings
|
||||
// and will be returned as strings.
|
||||
//
|
||||
// Needs to be further converted, because this returns an interface{}.
|
||||
func (v *VARIANT) Value() interface{} {
|
||||
switch v.VT {
|
||||
case VT_I1:
|
||||
return int8(v.Val)
|
||||
case VT_UI1:
|
||||
return uint8(v.Val)
|
||||
case VT_I2:
|
||||
return int16(v.Val)
|
||||
case VT_UI2:
|
||||
return uint16(v.Val)
|
||||
case VT_I4:
|
||||
return int32(v.Val)
|
||||
case VT_UI4:
|
||||
return uint32(v.Val)
|
||||
case VT_I8:
|
||||
return int64(v.Val)
|
||||
case VT_UI8:
|
||||
return uint64(v.Val)
|
||||
case VT_INT:
|
||||
return int(v.Val)
|
||||
case VT_UINT:
|
||||
return uint(v.Val)
|
||||
case VT_INT_PTR:
|
||||
return uintptr(v.Val) // TODO
|
||||
case VT_UINT_PTR:
|
||||
return uintptr(v.Val)
|
||||
case VT_R4:
|
||||
return *(*float32)(unsafe.Pointer(&v.Val))
|
||||
case VT_R8:
|
||||
return *(*float64)(unsafe.Pointer(&v.Val))
|
||||
case VT_BSTR:
|
||||
return v.ToString()
|
||||
case VT_DATE:
|
||||
// VT_DATE type will either return float64 or time.Time.
|
||||
d := uint64(v.Val)
|
||||
date, err := GetVariantDate(d)
|
||||
if err != nil {
|
||||
return float64(v.Val)
|
||||
}
|
||||
return date
|
||||
case VT_UNKNOWN:
|
||||
return v.ToIUnknown()
|
||||
case VT_DISPATCH:
|
||||
return v.ToIDispatch()
|
||||
case VT_BOOL:
|
||||
return v.Val != 0
|
||||
}
|
||||
return nil
|
||||
}
|
11
vendor/github.com/go-ole/go-ole/variant_386.go
generated
vendored
11
vendor/github.com/go-ole/go-ole/variant_386.go
generated
vendored
@ -1,11 +0,0 @@
|
||||
// +build 386
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
}
|
12
vendor/github.com/go-ole/go-ole/variant_amd64.go
generated
vendored
12
vendor/github.com/go-ole/go-ole/variant_amd64.go
generated
vendored
@ -1,12 +0,0 @@
|
||||
// +build amd64
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
_ [8]byte // 24
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user