Module: Snarl::SnarlAPI

Extended by:
DL::Importable
Included in:
Snarl
Defined in:
lib/snarl.rb

Overview

This is the lowlevel API implemenation using DL and a few handy constants from the snarl api and the Win32 API Note that I have jump through some hoops to get the array of characters to work corretly – if you know a better way please send me ([email protected]) a note.

Constant Summary collapse

SNARL_SHOW =
1
SNARL_HIDE =
2
SNARL_UPDATE =
3
SNARL_IS_VISIBLE =
4
SNARL_GET_VERSION =
5
SNARL_REGISTER_CONFIG_WINDOW =
6
SNARL_REVOKE_CONFIG_WINDOW =
7
SNARL_TEXT_LENGTH =
1024
WM_COPYDATA =
0x4a
SnarlStruct =
struct [
  "int cmd",
  "long id",
  "long timeout",
  "long data2",
  "char title[#{SNARL_TEXT_LENGTH}]",
  "char text[#{SNARL_TEXT_LENGTH}]", 
  "char icon[#{SNARL_TEXT_LENGTH}]",                     
]
CopyDataStruct =
struct [
  "long dwData",
  "long cbData",
  "void* lpData",
]

Class Method Summary collapse

Class Method Details

.send(ss) ⇒ Object

Send the structure off to snarl, the routine will return (if everything goes well) the result of SendMessage which has an overloaded meaning based upon the cmd being sent



60
61
62
63
64
65
66
67
68
# File 'lib/snarl.rb', line 60

def self.send(ss)
  if isWindow(hwnd = findWindow(nil, 'Snarl'))
    cd = CopyDataStruct.malloc
    cd.dwData = 2
    cd.cbData = ss.size
    cd.lpData = ss.to_ptr
    sendMessage(hwnd, WM_COPYDATA, 0, cd.to_ptr)
  end
end

.to_cha(str) ⇒ Object

character array hoop jumping, we take the passed string and convert it into an array of integers, padded out to the correct length to_cha –> to character array I do this as it seems necessary to fit the DL API, if there is a better way please let me know



52
53
54
55
# File 'lib/snarl.rb', line 52

def self.to_cha(str)
  result = str.split(/(.)/).map { |ch| ch[0] }.compact
  result + Array.new(SNARL_TEXT_LENGTH - result.size, 0)
end