getOpacity method

  1. @override
double getOpacity()
override

Implementation

@override
double getOpacity() {
  var exStyle = GetWindowLongPtr(_windowId, GWL_EXSTYLE);
  if (0 == exStyle & WS_EX_LAYERED) return 1.0;

  const maxAlpha = 255;
  double retOpacity = 255;

  final lpcrKey = malloc<Uint32>();
  final lpbAlpha = malloc<Uint8>();
  final lpdwFlags = malloc<Uint32>();
  try {
    GetLayeredWindowAttributes(_windowId, nullptr, lpbAlpha, nullptr);
    retOpacity = lpbAlpha.value / maxAlpha;
  } catch (e) {
    log(e.toString());
  } finally {
    malloc.free(lpcrKey);
    malloc.free(lpbAlpha);
    malloc.free(lpdwFlags);
  }
  return retOpacity;
}